具有两个patial视图(均包含表单)的视图会在提交一个表单时对两个表单进行验证

时间:2014-04-16 09:27:11

标签: asp.net-mvc forms asp.net-mvc-partialview

我有一个父视图,上面有两个部分视图。

每个部分视图都有自己的形式,我发布到。

当我提交其中一个表格时,他们都验证(服务器端)。

我该如何防止这种情况?

两个表单都设置为发布到父视图。

代码

登录页面,其中包含用于签名的部分视图和用于注册的部分视图。两个部分视图都包含表单。

Index.cshtml

    @{Html.RenderAction("LogOn", "LogOn");}
    @{Html.RenderAction("Register", "Register");}

SignInController.cs

public class SignInController : Controller
{
    public ActionResult Index()
    {
        return this.View();
    }
}

_LogOn.cshtml

    @using (Html.BeginForm("Index", "SignIn", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
    {

LogOnController.cs

    [HttpPost]
    public ActionResult LogOn(LogOnModel model)
    {

        return this.PartialView("_LogOn", model);
    }

_Register.cshtml

    @using (Html.BeginForm("Index", "SignIn", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
    {

RegisterController.cs

    [HttpPost]
    public ActionResult Register(RegisterModel model)
    {

        return this.PartialView("_Register", model);
    }

0 个答案:

没有答案