[英]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.