我目前正在为其中一个模型开发编辑页面,因此我在路由配置中将编辑页面设置为默认值。问题是,由于某种原因,它触发了Post事件而不是Get。示例非常简单:
[HttpGet]
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
JobLine jobLine = db.JobLines.Find(id);
if (jobLine == null)
{
return HttpNotFound();
}
Mapper.CreateMap<JobLine, JobLineDTO>();
JobLineDTO joblineDTO = Mapper.Map<JobLine, JobLineDTO>(jobLine);
return View("Create",joblineDTO);
}
[HttpPost]
public ActionResult Edit(JobLineDTO jobLineDTO)
{
return View();
}
这种行为可能是什么原因?
路线配置
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Joblines", action = "Edit", id = 1 /*UrlParameter.Optional*/ }
);
}