ASP.NET MVC 2:jQuery的通话动作,更新视图? [英] ASP.NET MVC 2: jQuery call Action, update View?

查看:80
本文介绍了ASP.NET MVC 2:jQuery的通话动作,更新视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制器:

public ActionResult Index()
        {

            // not using the interface right now
            DealsRepository _repo = new DealsRepository();
            var deals = _repo.GetDeals("<Request><ZipCode>92618</ZipCode></Request>");

            return View(deals);
        }

        [HttpPost]
        public ActionResult Index(string data)
        {

            // not using the interface right now
            DealsRepository _repo = new DealsRepository();
            var deals = _repo.GetDeals(data);

            return View(deals);
        }

jQuery的:

jQuery:

var url = '<%: Url.Action("Index", "Deal") %>';
var data = '<Request><ZipCode>92618</ZipCode></Request>';

$.post(url, data, function (result) {
    alert(result);
});

我想要做的就是刷新(重装)的更新模型视图...我不想使用jQuery来更新内容。 Relaod与更新的模型视图。

What I'm trying to do is refresh (reload) the View with the updated Model... I don't want to use jQuery to update the content. Relaod the View with the updated Model.

换句话说,一旦用户在他们的搜索一些改进或选择一个过滤器,我需要拨打电话,并与最新型号的搜索结果重新加载页面。

推荐答案

您不需要JavaScript就发布一个形式,这是什么,似乎你正在尝试做的。

You don't need javascript at all to post a form, which is what it seems you are trying to do.

只需添加一个提交按钮到你的HTML表单。当点击提交按钮的形式将被张贴到与HTML表单关联的控制器和动作。该控制器和行动将返回一个ActionResult这将是你的刷新视图如果你选择...

Just add a submit button to your html form. When the submit button is clicked the form will be posted to the controller and action associated with the html form. That controller and action will return an ActionResult which will be your refreshed view if you so choose...

在你看来,你可以做这样的事情:

In your view you can do something like this:

<%Html.BeginForm("ActionName", "ControllerName", FormMethod.Post); %>
<!-- more form fields here -->
<input type="submit" value="Go"/>
<%Html.EndForm(); %>

这篇关于ASP.NET MVC 2:jQuery的通话动作,更新视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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