http://example.com/Product/Index/pid219
Где:
- Продукт — имя контроллера
- Индекс — имя метода и
- pid219 — идентификатор продукта
http://example.com/Product/pid219
ИЛИ
http://example.com/Product/name-of-the-product/pid219
Итак, я изменил RouteConfig.cs следующим образом:
Код: Выделить всё
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "ProductRoute1",
url: "{controller}/{id}",
defaults: new { controller = "Product", action = "Index", id = "" }
);
routes.MapRoute(
name: "ProductRoute2",
url: "{controller}/{ignore}/{id}",
defaults: new { controller = "Product", action = "Index", id = "" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Например: нажатие кнопки «Войти» не работает.
Имя контроллера — SignIn, и есть два метода — Index (который загружает страницу), SignInUser (который запускается по запросу ajax)
Когда я нажимаю кнопку «Войти», теперь используется метод Index вместо метода SignInUser.
Код: Выделить всё
function SignInUser() {
$.ajax({
type: "POST",
url: '@Url.Action("SignInUser", "SignIn")',
data: '',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
}
});
}
Подробнее здесь: https://stackoverflow.com/questions/524 ... ute-in-mvc
Мобильная версия