我如何制作自定义 HTML Helper 就像Html.CheckBoxFor() 我制作依赖于数据库的动态表单输入一样,所以我需要生成我的自定义 HTML 元素我尝试PartialView通过ajax request返回并将返回HTML的添加 PartialView到DOM,但需要更多时间,具体取决于服务器端 $.ajax({ type: "GET", url: "@Url.Action("FindTransactionForInternal", "Transactions")", contentType: 'application/json; charset=utf-8', dataType: 'html', data: { transId:transId }, success: function (response) { $('#internaldetails').html(response); } });
1 回答
![?](http://img1.sycdn.imooc.com/54584cfb0001308402200220-100-100.jpg)
慕村9548890
TA贡献1884条经验 获得超4个赞
这是如何制作自定义 HTML Helper 的示例
public static class HelpersExtensions
{
public static string CustomCheckBoxFor(this HtmlHelper helper, string target, string text)
{
return String.Format("<input type='checkbox' for='{0}'>{1}</input>", target, text);
}
}
注意: Html helper 不能从数据库中获取信息,只能使用传递给参数的值。
可以做的是在控制器中获取信息并传递给模型,因此模型将参数传递给自定义 html 助手
添加回答
举报
0/150
提交
取消