繁体   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