[英]Control not rendering in MVC view
在开始使用MVC中的ascx控件之前,让我开始说这不是我想要做的! 但是,我之上的力量希望继续使用ascx控件。
我首先在控制器中使用以下命令:
public ActionResult _CreditReporting(int id)
{
return PartialView();
}
public static class myClass
{
public static string GenerateHtmlFromYourControl(this HtmlHelper helper, string contId)
{
var credControl = new _person_creditreporting_control();
credControl.ID = contId;
var htmlWriter = new HtmlTextWriter(new StringWriter());
credControl.RenderControl(htmlWriter);
return htmlWriter.InnerWriter.ToString();
}
}
在我看来
@using ds_iDMS.Controllers
<div>
@{
Html.GenerateHtmlFromYourControl("_person_creditreporting_control.ascx");
}
</div>
一切似乎都工作正常,所有参数都正在传递等。但是,ascx页面未渲染,我不确定为什么
我会改变看法
@using ds_iDMS.Controllers
<div>
@Html.Raw(Html.GenerateHtmlFromYourControl("_person_creditreporting_control.ascx"))
</div>
Phil Haack有一个很好的快速参考指南,介绍了剃刀语法的不同方面。 到现在可能有点过时了,但是它仍然是非常有用的概述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.