加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 在同一个视图文件夹中的RenderPartial控件

发布时间:2020-12-15 20:30:16 所属栏目:asp.Net 来源:网络整理
导读:我的视图文件夹中有一个文件用户名为UserViewControl.cshtml. 我的代码在实际视图(Users.cshtml)中是: @Html.RenderPartial("RegisterViewControl") 错误:最好的重载方法匹配’System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.Helper
我的视图文件夹中有一个文件用户名为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") %>

所以同样的规则适用于剃须刀.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读