How to create a user control in MVC


I am using Visual Studio 2013 and MVC5 for developing web application. The scenario is that I have 3 different web applications with some common features. Now in MVC I want to create some sort of user control that contains View, code behind along with  javascript.
Now how I can create such control so that it can be used across all the applications.

Is there something like server controls or user controls (.ascx) that can be used in MVC application? If no any alternatives for these?


Steps here


Another method is control extensions. Create a public static class. inside that class you can extend any control(set of controls) you want.


public static class HtmlExtension
	public static IHtmlString CustomDropDownFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, int>> value, Expression<Func<TModel, string>> text, IList dataSource, string key, string css, string changeHandler = "")
	    Dictionary<string, object> attribute = new Dictionary<string, object>();
            attribute.Add("class", css);
            attribute.Add("id", key);

            attribute.Add("onChange", changeHandler);
            MvcHtmlString hdn = InputExtensions.HiddenFor(helper, text, new { id = key });
            MvcHtmlString dropDown = SelectExtensions.DropDownList(helper, "cmb" + key, new SelectList(dataSource, "Key", "Value"), attribute);
            return helper.Raw(hdn.ToHtmlString() + dropDown.ToHtmlString());

The above examples render a dropdown and hidden field. We can use this extension in our views just like other Html extensions. 

@Html.CustomDropDownFor(m => model.Id, m => model.Text, dropdowns, "controlname", "left select","OnChange(this)")

Hi girish.nehte,

Thanks for your post.

According to your description,


Is there something like server controls or user controls (.ascx) that can be used in MVC application

I think you can try to use partial view,partial view is like user control.

Please you can check these:

#ASP .NET MVC Partial Views

#How to Use Partial View in MVC3 and MVC4 with Examples

Hope this can be helpful.

Best Regards,


Leave a Reply