Register custom control in MVC3 ASPX Partial view

混江龙づ霸主 提交于 2019-12-23 03:39:10

问题


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.



来源:https://stackoverflow.com/questions/9554136/register-custom-control-in-mvc3-aspx-partial-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!