سؤال
قرأت الكثير من المنصب، وأنا لا أرى بلدي mystake.
يمكن للشخص الرجاء مساعدتي.
هناك بلدي العالمي
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute("UserName", "Account/{action}/{username}",
new { action = "EditProfile", controller = "Account" });
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
عندما أستخدم
<%= Html.ActionLink("Edit Account", "EditProfile", "Account", new { username = Html.Encode(Page.User.Identity.Name) },null) %>
حصلت على هذا عنوان URL
http: // localhost: 8458 / account / editprofile؟ اسم المستخدم = cboivin
إذا حاولت استدعاء عنوان URL مباشرةhttp: // localhost: 8458 / account / editprofile / cboivin
لا تعمل على ...
هناك طريقتي في حسابي
public ActionResult EditProfile(string username)
{
return View(ServiceFactory.UserAccount.GetUserByUserName(new GetUserByUserNameArgs(username)));
}
أنا لا أعرف أين خطأي. يمكن لأي شخص أن يساعدني ؟ شكرًا.
المحلول
يتم قراءة الطرق أعلى أسفل، يجب أن يكون "التقاط الكل" العام الماضي.
routes.MapRoute("UserName", "Account/{action}/{username}",
new { action = "EditProfile", controller = "Account" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
نصائح أخرى
حاول إزالة:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
وتذكر المزيد من الطرق العامة يجب أن تكون في أسفل جدول التوجيه، في حين يجب أن تأتي المزيد من الطرق المحددة في القمة.
لا تنتمي إلى StackOverflow