D'Arcy from Winnipeg
Solution Architecture, Business & Entrepreneurship, Microsoft, and Adoption

ASP.NET MVC: View Controls Not Accessible In Code Behind

Friday, February 15, 2008 3:39 PM

I was working in the MVC framework when I came accross an issue within my views. Although I was dropping controls onto the form, none of them were accessible from the code behind file. I also noticed that there weren't any designer files anywhere, which I thought was odd.

After some poking around it turns out that you need to convert your MVC projects to be web applications before you get the full ASP.NET feature set.

Just right click your project file and select 'Convert to Web Application' from the menu. Voila: you'll notice that your design files are back and you have access to your controls again.

D




Feedback

# re: ASP.NET MVC: View Controls Not Accessible In Code Behind

I encountered the same issue and your post really helped. 2/29/2008 12:22 AM | fn

# re: ASP.NET MVC: View Controls Not Accessible In Code Behind

The problem is that we have all been spoiled by the designer file that is normally associated with Web Application Projects. As you drop server controls on the form, controls are automatically declared in a partial class in the designer file. If you check out your ASP.NET MVC solution, you will notice the absence of these designer files. Adding them is as simple as right-clicking on the view file and choosing “Convert to Web Application“.


8/7/2012 7:16 PM | Pradip

Post a comment