ASP.NET Core MVC : actionlink parameter to use slashes (/) insted of questionmark (?) in a query string - asp.net-core-mvc

I would like to map a route that would be valid for any number of parameter passed as a query string for any controller and methods.
For instance:
/Area/Controller/Action?paraA=1&paraB=2
should be changed to
/Area/Controller/Action/paraA/1/paraB/2
The standard mapping only works for an id parameter. I want to update it so that it works for any number of parameters. Any suggestions?
Standard implementation is
app.MapControllerRoute(
name: "MyArea",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

According to your description, the asp.net core route template contains the a catch-all parameter.
You could put it like below:
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{*ids}");
If you put the /Area/Controller/Action/1/2/3/4 inside the url, the controller method will capture it like below:
Then you could use Split method to split it and use it.

Related

Using underscore synatx in URI with implicit controller in laravel

I know this:
If your controller action contains multiple words, you may access the action using "dash" syntax in the URI. For example, the following controller action on our UserController would respond to the users/admin-profile URI:
public function getAdminProfile() {}
Want to the know about:
If i want to use "underscore" synatx in the URI. Is it possible with implicit controllers.
Like want to use user/admin_profile in the URI. What would controller look like?
You can do something like this.
In your routes.php file add
Route::get('user/admin_profile', 'UserController#getAdminProfile');

Reordering parameters and controllers in the URI

I would like all my URLs in codeigniter to start with the first URI segment to be passed to the controller as a parameter.
Here is my use case:
For the url: http://www.example.com/site/page/1
The "Site" would be a parameter passed to the controller "page", "1" is also a parameter (and anything after it).
Would a Mod_Rewrite be more appropriate than codeigniter routing?
You can write it in routes for particular page like
$route['site/page/(:num)'] = 'page/site/$1';

MVC3 razor remote validation - Controller argument is always empty

I can call the controller but the argument (string) is always null.
All the examples I have found name the controller argument the same as the property we are validating remotely, sounds good/easy, but if you look at fiddler what is really being passed in is the name attribute from the input statement. Well that is problematic in that it is a subscripted name something like Person.EMailAddresses[0].Address, well I can't name my controller parameter like that.
So how do I get around this? There must be a way to specify the controllers parameter name in the remote() attribute?
It cannot be done using the default RemoteAttribute. This is a link to an example I posted of a reusable remote validation attribute, where you can specify the name of the controller, action and the name of the variable used to pass the value to the action.

Asp.net MVC putting # in the url

We are using Asp.net MVC, one of our requirement is to put '#' in the url something like
www.xyz.com/a-to-b/#date
i have registered the route below, it works fine for 'to' in the url but using # before the date i get a null data back. Is '#' some special character and required a different treatment.??
routes.MapRoute(
"routename",
"{origin}-to-{destination}/#{outDate}",
new
{
controller = "Home",
action = "ActionName",
});
The hash value (string starting from #) will never be sent to server. If you need access to the hash value you can use the following approach - How to get Url Hash (#) from server side .
Also it seems to me that you need to implement some kind of ajax navigation with history support. If I'm right then check this article - http://stephenwalther.com/blog/archive/2010/04/08/jquery-asp.net-and-browser-history.aspx

MVC subController

My application has the following module:
/groups/{id_group} -- > GroupController.php
My question is this,
/groups/{id_group}/events/{id_event}
Which controller should handle this?
If you are using groups/n/ as routing, you would want to use your framework's routing system to route to the event controller. Otherwise, it is the groups controller.
If you want to stick to just using the first parameter as the Controller, then consider using the further parameters as purely parts of the query string e.g
?controller=groups&itemId={id_group}&action=events&actionId={id_event)
and use the controller to route it to the correct place e.g.
$model->getGroup($id_group, 'events', $id_event);

Resources