我想讓我的頁面發佈到我的Web API控制器,而不是我的Area/Controller/Action。這是我到目前爲止,我已經嘗試使用這兩種Html.BeginForm和Ajax.Begin形式:Html.BeginForm路由到Web Api
@using (Ajax.BeginForm("", "", null, new AjaxOptions { HttpMethod = "POST", Url = "api/Standing" }, new { id = "frmStandingAdd", name = "frmStandingAdd" }))
@using (Html.BeginForm("", "api/Standing", FormMethod.Post, new { id = "frmStandingAdd", name = "frmStandingAdd" }))
但我不能讓任何張貼到根即http://domain/api/Standing
,而是後兩者的面積即http://domain/Areaname/api/Standing
。我如何讓它正確發佈?
更新:下面是我對相關區域的路線:
public override string AreaName
{
get
{
return "Areaname";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
string defaultLocale = "en-US";
context.MapRoute(
"Areaname_default",
"{languageCode}/Areaname/{controller}/{action}/{id}",
new { languageCode = defaultLocale, controller = "Main", action = "Index", id = UrlParameter.Optional });
context.MapRoute(
"History",
"{languageCode}/Areaname/{controller}/{action}/{year}",
new { controller = "History", action = "Season", year = UrlParameter.Optional });
}
而且我的Web API路線:
config.Routes.MapHttpRoute(
"DefaultApi",
"api/{controller}/{id}",
new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
"DefaultApiWithAction",
"api/{controller}/{action}/{season}",
new { id = RouteParameter.Optional }
);
請發表您的'routes' – haim770 2013-05-12 19:01:00