我的视图文件夹中有一个文件用户名为UserViewControl.cshtml.
我的代码在实际视图(Users.cshtml)中是:
@Html.RenderPartial("RegisterViewControl")
错误:最好的重载方法匹配’System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)’有一些无效的参数
整个视图文件夹可能会在将来移动,我不想像这样完全键入路径:
@Html.RenderPartial("~/Views/Users/RegisterViewControl.cshtml")
RegisterViewControl.cshtml中的代码:
@model SampleMVC.Web.ViewModels.RegisterModel @using (Html.BeginForm("Register","Auth",FormMethod.Post,new { Id = "ERForm" })) { @Html.TextBoxFor(model => model.Name) @Html.TextBoxFor(model => model.Email) @Html.PasswordFor(model => model.Password) }
这是一个由ajax提交的表单,但我想要viewmodel中的所有验证.
解决方法
应该是这样的:
@{Html.RenderPartial("RegisterViewControl");}
那是因为RenderPartial扩展方法没有返回任何东西.它直接写入输出.在aspx中,您可以使用它:
<% Html.RenderPartial("RegisterViewControl"); %>
代替:
<%= Html.RenderPartial("RegisterViewControl") %>
所以同样的规则适用于剃须刀.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。