路由数据而不是查询字符串?

时间:2015-09-26 13:39:32

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

我是MVC的新手。我有一个索引视图,显示一个表的列表。并且表的所有行都有Detail,Update和Delete链接按钮。我创建如下链接;

@Html.ActionLink("Detail", "Display", new { _ID = item.ID })
@Html.ActionLink("Update", "Update", new { _ID = item.ID })
@Html.ActionLink("Delete", "Delete", new { _ID = item.ID })

我的路线注册如下。他们在区域。

        context.MapRoute(
            name: "Assignments_Action",
            url: "Assignments/{action}/{_ID}",
            defaults: new { controller = "Assignments", _ID = UrlParameter.Optional }
        );

        context.MapRoute(
            name: "Assignments_List",
            url: "Assignments/{action}/{_Page}",
            defaults: new { controller = "Assignments", _Page = UrlParameter.Optional }
        );
        context.MapRoute(
            "Assignments_default",
            "Assignments/{controller}/{action}/{_ID}",
            new { controller = "Home", action = "Index", _ID = UrlParameter.Optional }
        );

我的控制器如下;

public ViewResult Display(int _ID)
{
    //blabla
    return View(assignmentsModel);
}

[HttpGet]
public ViewResult Update(int _ID)
{
    //blabla
    return View("Index");
}

[HttpPost, ValidateInput(false)]
public RedirectToRouteResult Update(AssignmentsModel _assignmentsModel)
{
    //blabla
    return RedirectToAction("Index");
}

public ActionResult Delete(int _ID)
{
    //blabla
    return View();
}

但链接是使用查询字符串创建的:localhost:1111/Assignments/Display?_ID=399

不像routedata:localhost:1111/Assignments/Display/399

如果我自己键入localhost:1111/Assignments/Display/399这样的网址,则可以正常使用。

但它本身并不是创造出来的。

0 个答案:

没有答案