[英]Control not rendering in MVC view
Before getting flack about using ascx controls in MVC let me preface that this is not what I would like to do! 在开始使用MVC中的ascx控件之前,让我开始说这不是我想要做的! However the powers above me would like to continue to use the ascx control.
但是,我之上的力量希望继续使用ascx控件。
I started by using the following in my controller: 我首先在控制器中使用以下命令:
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();
}
}
and the following in my view 在我看来
@using ds_iDMS.Controllers
<div>
@{
Html.GenerateHtmlFromYourControl("_person_creditreporting_control.ascx");
}
</div>
Everything seems to be working properly and all the parameters are being passed etc. The ascx page is not rendering however and I am not sure why 一切似乎都工作正常,所有参数都正在传递等。但是,ascx页面未渲染,我不确定为什么
I would change the view to 我会改变看法
@using ds_iDMS.Controllers
<div>
@Html.Raw(Html.GenerateHtmlFromYourControl("_person_creditreporting_control.ascx"))
</div>
Phil Haack has a good quick reference guide to different bits of the razor syntax. Phil Haack有一个很好的快速参考指南,介绍了剃刀语法的不同方面。 it might be a little outdated by now, but it is still a very useful overview.
到现在可能有点过时了,但是它仍然是非常有用的概述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.