这可能是堆栈溢出时这里最愚蠢的问题。但是我正在从我正在使用的一些代码中获得最奇怪的结果。我试图让jqGrid在我的MVC 2应用程序中工作。为什么我要下载一个aspx页面,而不是在MVC 2中导航到这个页面
我的家庭控制器有一个索引和GridData的操作方法... GridData需要4个参数,其中2个不能为空,所以我添加一个defalutValue属性值为1给他们。该指数控制器重定向到的GridData操作方法至极然后打开了的GridData看法......我也不在这个函数返回的看法,但我回一个JSON变量...
[Authorize(Roles="testRole")]
public ActionResult Index(string nextButton)
{
ViewData["identity_Name"] = identity.Name;
if (nextButton != null)
return RedirectToAction("GridData");
return View("Index");
}
public ViewResult windowsID()
{
return View();
}
public ActionResult GridData(string sidx, string sord, [DefaultValue(1)] int page, [DefaultValue(1)] int rows)
{
var jsonData = new
{
total = 1, // we'll implement later
page = page,
records = 3, // implement later
rows = new[]
{
new {id = 1, cell = new[] {"1", "-7", "Is this a good question?"}},
new {id = 2, cell = new[] {"2", "15", "Is this a blatant ripoff?"}},
new {id = 3, cell = new[] {"3", "23", "Why is the sky blue?"}}
}
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
}
这里是我的大多数Javascript代码。
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#list").jqGrid({
url: '/Home/GridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['Id', 'Votes', 'Title'],
colModel: [
{ name: 'Id', index: 'Id', width: 40, align: 'left' },
{ name: 'Votes', index: 'Votes', width: 40, align: 'left' },
{ name: 'Title', index: 'Title', width: 200, align: 'left'}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/smoothness/images',
caption: 'My first grid'
});
});
似乎是合理的吗?为什么它会下载页面而不是重定向到它?我可能会在这里做错什么。我想我的确很多,但我认为我只是缺少一些简单的东西。
很确定不是这样。但是这确实给了我一个想法。我重定向到特定的控制器和操作。不幸的是我得到了同样的结果。我保证,如果我尝试过,我永远无法做到这一点。 – SoftwareSavant 2011-06-02 17:09:04
@ user729820:检查你的路由。 – LeftyX 2011-06-02 17:20:16
一直在看我的路由。关于我的路由引擎究竟会让我下载页面而不是重定向到它? – SoftwareSavant 2011-06-02 18:11:18