修改index.aspx文件,然后获取http 404

时间:2012-04-02 15:26:18

标签: javascript jquery asp.net-mvc

我一直在玩jQuery网格控件,并对index.aspx文件进行了以下更改:

由此:

  <script type="text/javascript">
      jQuery(document).ready(function() {
          jQuery("#list").jqGrid({
              url: '/Home/DynamicGridData/',
              datatype: 'json',
              mtype: 'POST',
              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: 400, align: 'left'}],
              pager: jQuery('#pager'),
              rowNum: 10,
              rowList: [5, 10, 20, 50],
              sortname: 'Id',
              sortorder: "desc",
              viewrecords: true,
              imgpath: '',
              caption: 'My first grid'
          });
      }); 
    </script>  

对此:

  <script type="text/javascript">
     jQuery(document).ready(function() {
              jQuery("#list").jqGrid({
              url: '/Home/GridData/',
              datatype: 'json',
              mtype: 'POST',
              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: 400, align: 'left'}],
              pager: jQuery('#pager'),
              rowNum: 10,
              rowList: [5, 10, 20, 50],
              sortname: 'Id',
              sortorder: "desc",
              viewrecords: true,
              imgpath: '',
              caption: 'My first grid'
          });
      }); 
    </script>  

现在我发现每当我加载项目时,我都会收到HTTP 404错误,并且我对此问题感到吃惊:我更改了页面应该加载的操作。

当我将其更改回来时,错误仍然存​​在。

有没有人见过这个?

1 个答案:

答案 0 :(得分:1)

根据您的代码,您的第一个操作是DynamicGridData 您已将其更改为GridData
因此,您必须declare an action GridData,并将其标记为HttpPost属性:

[HttpPost]
public ActionResult GridData(SomeEditModel form)
{
    if (IsNotValid)
    {
        return ShowAView(form);
    }

    DoActualWork();

    return RedirectToSuccessPage();
}