Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc ASP.NET MVC-在视图之间传递值_Asp.net Mvc_View - Fatal编程技术网

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>

我想现在不难理解为什么你的锚不起作用了