部分ASP.NET MVC视图提交 [英] Partial ASP.NET MVC View submit

查看:257
本文介绍了部分ASP.NET MVC视图提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我ASP.NET MVC是新所以这个问题可能出现'笨',对不起。

I'm new in ASP.NET MVC so the question could appear 'stupid', sorry.

我有我的主页视图内的局部视图。

I have a Partial View inside my Home view.

局部视图提交表单调用的操作方法HomeController的内部。

The Partial View submit a form calling an Action Method inside the HomeController.

它正常工作与服务器的验证,问题是该职位后才局部视图呈现。

It works fine with server validation, the problem is that after the post only the Partial View is rendered.

如何渲染后门柱整个家庭的看法?

How can I render the entire Home view after post?

关于code:

里面PartialView我有一个表格:

Inside PartialView I have a form:

<% using (Html.BeginForm("Request", "Home")) { %>

的要求就是我的HomeController中定义的ActionResult的。

Request is a ActionResult defined inside my HomeController.

[HttpPost]
public ActionResult Request(RequestModel model)
{
  if (ModelState.IsValid)
  {
    // Saving data .....
  }
  else
  {
     // Show Server Validation Errors
     return View();
  }
}

这时,后门柱的ASCX显示服务器验证错误回报,但只有PartialView ASCX code呈现。
该URL看起来像这样的帖子后:

At this time, after the post, the ascx shows the server validation erros but only the PartialView ascx code is rendered. The Url looks like this after the post:

http://xxxxxxxxxxx/Home/Request

我要的是展示,里面显示服务器验证错误的ASCX整个主页查看的内容。

What I want is showing the entire Home view with the ascx inside showing server validation errors.

推荐答案

尝试做局部提交使用jQuery:

Try to do a partial submit using jQuery:

<script type="text/javascript">
$(document).ready(function () {
    $("input[type=submit]").live("click", function () {
        var f = $("input[type=submit]").parents("form");
        var action = f.attr("action");
        var serializedForm = f.serialize();
        $.ajax({
            type: 'POST',
            url: action,
            data: serializedForm,
            success: function (data, textStatus, request) {
                if (!data == "") {
                    // redisplay partial view
                    $("#formDiv").html(data);
                }
                else {
                    // do whatever on sucess
                }
            }
        });
        return false;
    });
});
</script>

假设你的视图/ ASCX / HTML是这样的:

Assuming your view/ascx/HTML is something like this:

<div id="formDiv">
    <% Html.RenderAction("Request"); %>
</div>

这篇关于部分ASP.NET MVC视图提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆