ASP.NET MVC Map String Url To A Route Value Object -


I am creating a modular ASP.NET MVC application using fields. In essence, I have created a greedy path that captures all the routes beginning with {apps} / {* catchAll}.

Here is the verb:

  // get / application / index Public ActionRashult Index (string app, object catchold) {// forward partial view ViewData ["PartialRequest"] = new partial spacing (all catching); // it is said in the viewing page and uses partial request class to return partial view}  

Example:

URL "/ app / Accounting / logon "will then cause the index action to pass in" partial vacancy "/ accounts / logon", but will be the reason for passing as a string value.

  // Partial Request Manufacturer Public Partial Request (Object Route Value) {RouteValueDictionary = new RouteValueDictionary (routeValues); }  

In this case, the root value will not return any values ​​for the dictionary mode, whereas if I specify a path in the index action:

  ViewData ["partialRequest"] = new partial space (new {controller = "account", verb = "logon"});  

This works, and the route data value contains the "controller" key and an "action" key; Whereas, the keys are empty, and so the rest of the class is not working.

So my question is, how can I change "/ account / logon" in the catch "new {controller =" account ", action =" logon "}" ??

If it is not clear, then I will explain more! :)

Matt

This is "closest to me", but it does not clearly work for complex routes:

  // Split Price in Sir var var pathParts = catchAll.ToString () Split (new four [] {'/'}, string split option. RemoveEmptyEntries); // looks like a hack cat ALL = new {controller = route ports [0], action = route pars [1]};  

You should know what all the parts are in the catch. Then you have to parse it manually (like you are doing in your example or use regexp).

Why do you want to do something like this? Perhaps there is a better way.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -