एक जंगली अनुमान:
शायद आपका मार्ग डिफ़ॉल्ट मार्ग के बाद पंजीकृत था। इसे अपने ग्लोबल.एक्सएक्स के अंदर पहले रूट के रूप में रखें, फिर यह काम करेगा।
नीचे की तरह:
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Details", // Route name
//Put action instead of details
"{home}/{action}/{id}/{name}", // URL with parameters
new
{
controller = "Home",
action = "Details",
id = UrlParameter.Optional,
name = UrlParameter.Optional
} // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
अद्यतन
@Simon सही है, लेकिन अगर आप चाहते हैं यदि आप किसी अन्य तरीके से उपयोग कर सकते हैं।
केवल एक क्रिया विधि के लिए काम करने के मार्ग के लिए, निम्न कोड का उपयोग करें।
इस प्रकार की कोई समस्या बनाएँ:
public class EqualConstraint : IRouteConstraint {
private string _match = String.Empty;
public EqualConstraint(string match) {
_match = match;
}
public bool Match(System.Web.HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) {
return string.Equals(values[parameterName].ToString(), _match);
}
}
और फिर नीचे की तरह अपना रूट बदलें:
routes.MapRoute(
"Details", // Route name
//Put action instead of details
"{home}/{action}/{id}/{name}", // URL with parameters
new
{
controller = "Home",
action = "Details",
id = UrlParameter.Optional,
name = UrlParameter.Optional
}, // Parameter defaults
new {
controller = new EqualConstraint("Home"),
action = new EqualConstraint("Details")
}
);
actionlink ठीक काम किया जब ऊपर मार्ग डिफ़ॉल्ट मार्ग से पहले जोड़ा गया है। हालांकि, डिफ़ॉल्ट अब/होम/विवरण – Danny