I am trying to remove Details
from http://localhost:1985/Materials/Details/2/Steel
but some how my route doesn't seem to work...
Edit:
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 = "" }
);
placing the answer below in my route collection my index page failed to call to jsonresult controller method....
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);
}
}
and my index page has a jquery function which uses the json result....
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: "Materials/GetMaterials",
data: {'currentPage': (currentPage + 1) ,'pageSize':5},
contentType: "application/json; charset=utf-8",
This jquery function doesn't seem to call the jsonresult controller method...... But if i specify Default
route first it works...
When inspected through firebug it shows this,
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