c# - How do I get ASP.NET to route a controller properly? -
i have in controller:
public actionresult details(int? id) { if(id == null) { return new httpstatuscoderesult(httpstatuscode.badrequest); } sales salerecord = new sales(); var result = salerecord.getsalesorderheader((int)id); return view(result); } however if browse /controllername/details/5 error:
"server error in '/' application. - view 'details' or master not found or no view engine supports searched locations."
the strange thing if use asp.net scaffolding generate view, details part of works fine. it's same code have above well.
here's routeconfig.cs, if that's relevant:
public class routeconfig { public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( name: "default", url: "{controller}/{action}/{id}", defaults: new { controller = "home", action = "index", id = urlparameter.optional } ); } } so why scaffolding controller works fine, without having specific added routeconfig, yet controller details method not working?
there should more detail in error locations have been searched. did put break point in controller , checked if being hit?
try
return view((object)result); instead of
return view(result) cause calling overload view(string viewname)
if doesn't work, try specify viewname explicitly this:
return view("viewname", name); additionally, check folder structure. mvc looks views (like index) under views folder have under folder named after controller (except partial views).
Comments
Post a Comment