开发者

ASP.NET MVC URLs - Correct approach

开发者 https://www.devze.com 2023-04-05 08:43 出处:网络
Currently my project has a page domain/cocktail which displays a list of all cocktails. If user wants to filter the list he can choose sorting order, cocktail\'s starting letter and strength. So url w

Currently my project has a page domain/cocktail which displays a list of all cocktails. If user wants to filter the list he can choose sorting order, cocktail's starting letter and strength. So url will look like domain/cocktail?letter=B&sort=nu&strength=2&page=4.

As I've read it is not the best choice to use such urls. What approach can you suggest to get SEO-friendly URLs with t开发者_如何学Che same functionality.


ASP.NET MVC applications use the ASP.NET routing system, which decides how URLs map to particular controllers and actions.

Under default routing system when a browser requests http://yoursite/Home, it gets back the output from Controller's action method. Therefore if you use CoctailList action method to derive the list from backend, user will need to point at http://yoursite/Controller/CoctailList


In your situation, I would POST the search criteria, but I would put the page on end of the URL like:

domain/cocktail/2
domain/cocktail/3

You can post the data by creating a JSON object:

var viewModel = new Object();
viewModel.Letter = "B";
viewModel.Sort = "nu";
$.post("/domain/cocktail/" + page, viewModel, function () { });
0

精彩评论

暂无评论...
验证码 换一张
取 消