asp.net mvc - Dynamic Routing in mvc -
recently attend on interview, asking dynamic routing in mvc.
question how dynamically route action method depending upon parameter string or int.
for example :
public actionresult add(datatype variable) { //depending upon value asking how redirect. }
redirects aren't handled routing, it's handled actions executed.
i suppose meant how create routing rules execute action foo if data type string, , how execute action bar if data type int.
you use routing constraints, below i've added screenshot of supported constraints.
this how use them
public class homecontroller: controller { // foobar.com/home/123 [route("home/{id:int}")] public actionresult foo(int id) { return this.view(); } // foobar.com/home/onetwothree [route("home/{id:alpha}")] public actionresult bar(string id) { return this.view(); } } more information can found here.

Comments
Post a Comment