Details
から削除しようとしてhttp://localhost:1985/Materials/Details/2/Steel
いますが、ルートがうまくいかないようです...
編集:
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
最初にルートを指定すると機能します...
firebug で検査すると、これが表示されます。
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