簡體   English   中英

擴展@ Url.Action以傳遞多個動作

[英]Extend @Url.Action to pass multiple actions

我正在嘗試使用@ Url.Action通過URL傳遞多個參數,從而可以使用RouteAttribute讀取額外的參數

<li><a class="survey-button" href="
@Url.Action("Survey",(Model.SurveyID).ToString(),"Page"(Model.PageNumber).ToString())
">Previous</a></li>

//localhost:8080/Survey/1/Page/1
[Route("Survey/{surveyID}/Page/{pageNumber}")]
public ActionResult Page(int surveyID, int pageNumber)
{
...

我知道我可以通過查詢字符串傳遞這些信息,但是出於清潔的原因,這不是首選。

您需要將參數包裝在RouteValueDictionary或匿名對象中(更輕松)。 我假設您的控制器名稱為SurveyController

@Url.Action("Page", "Survey", new {surveyId = Model.SurveyId, pageNumber = Model.PageNumber})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM