我正在使用 Route 属性,我想使用Url.Action生成URL。
我在区域中有一个控制器,并且有两个ActionResult方法。我可以为其中一个生成,而不能为另一个生成。
[Route("kat/{binaId:int}")]
public ActionResult Kat(int binaId)
{
...
...
...
return View();
}
查看:
<a href="@Url.Action("Kat","Bina", new { binaId = item.BinaId })" class="btn m-btn--pill btn-primary m-btn m-btn--custom"> Link </a>
它产生了:
../ kat / 1
是真的。
同一控制器中还有一个动作结果:
[Route("daireekle/{katId:int}")]
public ActionResult DaireEkle(int katId)
{
return View(_uow.Daire.KataGoreDaireleriGetir(katId, HttpContext));
}
查看:
<a href="@Url.Action("DaireEkle","Bina", new { katId = item.KatId })" class="m-btn btn btn-success">Link</a>
它生成:
../ daireekle?katId = 1
Global.asax.cs
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
UnityConfig.RegisterComponents();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AntiForgeryConfig.UniqueClaimTypeIdentifier = "IsletmeId";
AntiForgeryConfig.UniqueClaimTypeIdentifier = "KullaniciId";
AntiForgeryConfig.UniqueClaimTypeIdentifier = "KullaniciTamAd";
AntiForgeryConfig.UniqueClaimTypeIdentifier = "KullaniciEposta";
}
IsletmeAreaRegistration.cs
public class IsletmeAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Isletme";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
}
}
RouteConfig.cs:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "WEBUI.Controllers" }
);
}
}
这是怎么了?
答案 0 :(得分:0)
我删除并再次创建actionresult和view。好了有趣的..