在Route Config中将编辑页面设置为默认设置以进行开发触发HTTPOST

时间:2015-06-13 08:13:00

标签: asp.net-mvc asp.net-mvc-4

我目前正在为其中一个模型开发编辑页面,因此我在路由配置中将编辑页面设置为默认值。问题是,由于某种原因,它触发了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*/ }
    );
}

0 个答案:

没有答案