操作链接未将值传递给控制器​​操作的值

时间:2015-04-28 14:57:01

标签: asp.net-mvc

我有以下MVC控制器操作:

public async Task<ActionResult> SelectMember(int memberId = 0, String returnUrl = "")
{
    if (memberId > 0)
    {
        /* Save selected member id ... */

        if (!String.IsNullOrEmpty(returnUrl))
            return RedirectPermanent(returnUrl);

        return RedirectToAction("Index");
    }
    return View();
}

我使用给定的链接:

  

本地主机:61286 /生成器/ SelectMember MEMBERID = 1&安培; RETURNURL =%2FBuilder%2FSelectArea

但是当使用此链接调用SelectMember时,memberId始终为0. returnUrl是正确的。

这是相关的剃须刀视图:

@using MyApp.Web.Languages
@model IEnumerable<MyApp.Web.Models.Member>

@{
    ViewBag.Title = @Builder.SelectMemberTitle;
}

<h2>@Builder.SelectMemberTitle</h2>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Description)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Description)
        </td>
        <td>
            @Html.ActionLink(Builder.SelectButton, "SelectMember", new { memberId = item.MemberId, returnUrl = ViewBag.ReturnUrl })
        </td>
    </tr>
}

</table>

这是我的路线配置:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapMvcAttributeRoutes();

        routes.MapRoute(
            name: "Categorized",
            url: "{controller}/{action}/{category}/{id}",
            defaults: new { }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

0 个答案:

没有答案