Register custom control in MVC3 ASPX Partial view

2019-05-30 15:06发布

问题:

I ask a relevant question here and as I find there is no way to use custom control in Razor views, so I get to add new ASPX partial view to use custom control, my custom control is a dll that I added to References then define Partial view as the following:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
<%@ Register Assembly="JQControls" Namespace="JQControls" TagPrefix="PersianDatepicker" %>
<PersianDatepicker:JQLoader ID="jqdb" runat="server" />
<PersianDatepicker:JQDatePicker ID="jqdp1" runat="server" Regional="fa" />

I write the exact code in ASPX Web form and worked correctly but there is an exception in MVC:

Error executing child request for handler 
'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'.

Exception of type 'System.Web.HttpUnhandledException' was thrown.

Object reference not set to an instance of an object.

So does any one have any idea about it?

Another question is how can I define a Html Helper for this user control (With dll and I have not access to code) ?

回答1:

make a html iframe into view, loading a aspx page!



回答2:

the "View" in MVC template should be standard HTML form.

you may use "Helper" to generate complex/re-useable HTML output but using any standard HTML+Javascript in UI is the way "MVC" works.

MVC allow parallel coding and HTML development. any developer who knows HTML+JS can create "View" without messing up your code.

this jquery plugin http://jqueryui.com/demos/datepicker/ can create custom DatePicker on client browser.