如何解决此URL问题?

问题描述 投票:1回答:1

enter image description here

public int[] Ids {
  get {
    return new int[] {
      1,
      2,
      3
    };
  }
  set {}
}
@Html.ActionLink("Approve", "Approval", new {
  id = item.Ids, approvalAction = "approve"
})

如何转换int32[] into ids=1&ids=2&ids=3

asp.net-mvc
1个回答
0
投票

您可以将数组作为逗号分隔的字符串发送,然后按如下所示将它们拆分为您的操作:

@Html.ActionLink("Approve", "Approval", new { id = string.Join("," , Ids), approvalAction = "approve" } )

您的操作:

public ActionResult YourAction(string id , string approvalAction)
{
    var ids = id.Split(',');
    //rest of your action method business
}

更新:另一种获得确切网址的方法是像这样创建您的网址:

var baseUrl = Url.Action("YourAction", "YourController", null, Request.Url.Scheme);
var uriBuilder = new UriBuilder(baseUrl);
uriBuilder.Query = string.Join("&", Ids.Select(x => "ids=" + x));
string url = uriBuilder.ToString();
url += "&approvalAction=approve"

您的操作将是这样的:

public ActionResult YourAction(int[] ids , string approvalAction)
{}
© www.soinside.com 2019 - 2024. All rights reserved.