asp.net mvc - An MVC 6 route does not perform as expected -
i have route:
routes.maproute(name: "trads", url: "test_3000/{action}/{traditional}", defaults: new { controller = "test_3000", action = "subset", traditional = urlparameter.optional });
and test_3000controller method:
// get: test_3000/subset?traditional=(chinese character) public actionresult subset(string traditional) { if (traditional == null) { return new httpstatuscoderesult(httpstatuscode.badrequest); } test_3000 test_3000 = db.test_3000.find(traditional); if (test_3000 == null) { return httpnotfound(); } return view(test_3000); }
this url works:
server/test_3000/subset?traditional=的
this url not work:
server/test_3000/subset/的
in latter case, 'traditional' null.
"traditional" column in sql table.
have tried this
routes.maproute(name: "trads", url: "test_3000/{action}/{traditional?}", defaults: new { controller = "test_3000", action = "subset", traditional = urlparameter.optional });
notice ? on traditional. also
public actionresult subset(string traditional = null) { ... }
so traditional explicitly set optional
Comments
Post a Comment