Asp.net mvc ASP.NET MVC-在视图之间传递值
我有两种观点:问答。从问题视图,我想重定向到答案视图的详细操作,创建操作,因此我放置了:Asp.net mvc ASP.NET MVC-在视图之间传递值,asp.net-mvc,view,Asp.net Mvc,View,我有两种观点:问答。从问题视图,我想重定向到答案视图的详细操作,创建操作,因此我放置了: @Html.ActionLink(Model.QuestionId.ToString(), "Create", "Answer", "Answer", new { id = Model.QuestionId }) 在回答中: public ActionResult Create(string id) { (...) return View(); } 但是Create中的id(strin
@Html.ActionLink(Model.QuestionId.ToString(), "Create", "Answer", "Answer", new { id = Model.QuestionId })
在回答中:
public ActionResult Create(string id)
{
(...)
return View();
}
但是Create中的id(stringid)总是空的。如何正确传递此值?您似乎选择了错误的
ActionLink
重载。试试这个:
@Html.ActionLink(Model.QuestionId.ToString(), "Create", "Answer", new { id = Model.QuestionId }, null)
您似乎选择了错误的
ActionLink
重载。试试这个:
@Html.ActionLink(Model.QuestionId.ToString(), "Create", "Answer", new { id = Model.QuestionId }, null)
您使用的ActionLink帮助程序错误。应该是:
@Html.ActionLink(
Model.QuestionId.ToString(), // linkText
"Create", // actionName
"Answer", // controllerName
new { id = Model.QuestionId }, // routeValues
null // htmlAttributes
)
这将产生
<a href="/answer/create/123">123</a>
由此产生:
<a href="/Answer/Create?Length=6" id="123">123</a>
我认为现在不难理解为什么你的锚不起作用。你使用了错误的ActionLink助手。应该是:
@Html.ActionLink(
Model.QuestionId.ToString(), // linkText
"Create", // actionName
"Answer", // controllerName
new { id = Model.QuestionId }, // routeValues
null // htmlAttributes
)
这将产生
<a href="/answer/create/123">123</a>
由此产生:
<a href="/Answer/Create?Length=6" id="123">123</a>
我想现在不难理解为什么你的锚不起作用了