這可能是堆棧溢出時這裏最愚蠢的問題。但是我正在從我正在使用的一些代碼中獲得最奇怪的結果。我試圖讓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