我試圖刪除http://localhost:1985/Materials/Details/2/Steel
Details
,但我的一些路線似乎並不怎麼工作的?「詳細信息」 asp.net的MVC路由似乎並沒有得到刪除
編輯:
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
看起來像這個一樣的問題http://stackoverflow.com/questions/2230165/asp-net-mvc-2-one-route-works-one-route-doesnt – R0MANARMY 2010-05-06 05:18:10