MVC重定向从jQuery的查看与参数 [英] MVC Redirect to View from jQuery with parameters

查看:119
本文介绍了MVC重定向从jQuery的查看与参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到有关这一些职位,但似乎无法得到它的工作。随着重定向我得到一个资源无法找到错误。

I have seen some posts relating to this but can't seem to get it to work. With the redirect I get a 'resource cannot be found error'.

我想重定向到一个详细信息页面。有一个在元素的ID,我存储为NestId,我希望最终能传递给视图。现在我只想重定向到详细信息页面,没有连接到它的模型或任何东西。我只想NestId使它有这样我可以用它来做更多的用AJAX调用。

I am trying to redirect to a Details page. There is an ID in element which I store as NestId that I want to eventually be able to pass to the View. Right now I just want to redirect to the details page, there isn't a model or anything attached to it. I just want the NestId to make it there so that I can use it to make more AJAX calls with it.

下面是我的jQuery的:

Here is my jQuery:

$('#results').on('click', '.item', function () {
            var NestId = $(this).data('id');
            var url = '@Url.Action("Details, Artists")'; 
            window.location.href = url; 
        })

下面是控制器上的功能:

Here is the function on the Controller:

public ActionResult Details(string NestId)
    {
        ViewBag.NestId = NestId; 
        return View();
    }

我不知道如果我要对这个正确的方式,但帮助将是AP preciated,我已经停滞在这一段时间。谢谢!

I'm not sure if I am going about this the right way but help would be appreciated, I've stalled on this for a while. Thanks!

推荐答案

如果您单击处理程序调用成功那么这应该工作:

If your click handler is successfully called then this should work:

$('#results').on('click', '.item', function () {
            var NestId = $(this).data('id');
            var url = "/Artists/Details?NestId=" + NestId; 
            window.location.href = url; 
        })

编辑:在给定的这种特殊情况下,该操作方法的参数是一个字符串,它是的可为空的,那么如果 NestId == NULL ,深得T引起任何异常可言,因为该模型绑定器不会抱怨。

In this particular case given that the action method parameter is a string which is nullable, then if NestId == null, won't cause any exception at all, given that the ModelBinder won't complain about it.

这篇关于MVC重定向从jQuery的查看与参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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