【发布时间】:2010-05-06 05:08:13
【问题描述】:
我正在尝试从 http://localhost:1985/Materials/Details/2/Steel 中删除 Details,但我的路线似乎不起作用...
编辑:
routes.MapRoute(
"Materials", // <-- Above default
"Materials/{id}/{name}",
new { controller = "Materials", action = "Details", id = "", name = "" }
);
routes.MapRoute(
"Default", // <-- Last route, kind of a "catch all"
"{controller}/{action}/{id}/{name}",
new { controller = "Materials", action = "Index", id = "", name = "" }
);
将下面的答案放在我的路由集合中,我的索引页面无法调用 jsonresult 控制器方法....
public class MaterialsController : Controller
{
public ActionResult Index()
{
return View("Materials");
}
public JsonResult GetMaterials(int currentPage,int pageSize)
{
var materials = consRepository.FindAllMaterials().AsQueryable();
var count = materials.Count();
var results = new PagedList<MaterialsObj>(materials, currentPage-1, pageSize);
var genericResult = new { Count = count, Results = results };
return Json(genericResult);
}
}
我的索引页面有一个使用 json 结果的 jquery 函数......
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: "Materials/GetMaterials",
data: {'currentPage': (currentPage + 1) ,'pageSize':5},
contentType: "application/json; charset=utf-8",
这个jquery函数好像没有调用jsonresult控制器方法……但是如果我先指定Default路由就可以了……
当通过萤火虫检查时,它会显示这一点,
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(Int32)' in 'CrMVC.Controllers.MaterialsController'. To make a parameter optional its type should be either a reference type or a Nullable type.<br>Parameter name: parameters
【问题讨论】:
-
看起来和这个stackoverflow.com/questions/2230165/…一样的问题
标签: asp.net-mvc url-routing detailsview