I'm trying to move from the Old WebForms .NET approach to the newer MVC version. I just can't seem to find a solution to this issue.

In my current projects I use a lot of custom made User Controls. These controls will in almost all cases have several properties that are populated as parameters in the code behind of the parent 'aspx' page.

The User Control will have an 'ascx' page where all the html and controls exist. There will also be a 'ascx.cs' file attached to it where all the properties, methods and back-end logic occur.

What I can't seem to work out is how this logical process works in MVC? The .ascx file is similar to an MVC PartialView... that does make sense.

But where do you store all the backend logic for a PartialView? How do I set multiple properties and construct the View based on these values?

I've seen some people suggesting you can still use .ascx files in MVC but I'm not sure this is the correct route to go down... certainly not the best practice route anyway?

I'll give a small example which may help:


<%@ Register tagprefix="CUSTOM" tagname="Weather" src="~/controls/Weather.ascx" %>

<CUSTOM:Weather ID="Weather" runat="server"></CUSTOM:Weather>


Weather.W_CountryCode = CountryCode;
Weather.W_CountryName = CountryName;


public string W_CountryCode { get; set; }
public string W_CountryName { get; set; }

Ok that is very basic structure of a control.

  • The control is embedded into the parent page.
  • Parameters are set in the code behind of the parent page.
  • The properties in the control will be used to collect the selected countries weather data from the database as well as running various other methods.

This easily reusable self contained code... I just can't see how you do the same thing in MVC? Where do you set the parameters... where is the code behind for the View stored?

Thanks in advance for any help

Related posts

Recent Viewed