使用参数将路由值放在@HtmlActionLink中

时间:2017-06-27 21:51:20

标签: asp.net-mvc razor

        <div class="form-group">
            @Html.LabelFor(model => model.Link, htmlAttributes: new { @class = "control-label col-md-3" })
            <div class="col-md-9">
                @Html.ActionLink("View", "Viewer", "Drawings", new { filePath = ....... }, new { target="_blank"})
            </div>
        </div>

我是mvc的新手,这里@ model.Link有文件名,我的困惑是如何将模型值放在filePath中,它是一个reqular文本框我会这样做@ Html.textboxFor( model =&gt; model.Link)。但我不能做lamba表达式错误。

1 个答案:

答案 0 :(得分:0)

嗨,下面的Actionlink将会对你有所帮助

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    object routeValues,
    object htmlAttributes
)

您的示例:

<div class="form-group">
            @Html.LabelFor(model => model.Link, htmlAttributes: new { @class = "control-label col-md-3" })
            <div class="col-md-9">
                @Html.ActionLink("View", "Viewer", "Drawings", new { filePath = Model.Link ,filename = Model.fileName ,...etc }, new { target="_blank"})
            </div>
        </div>

您的控制器操作方法看起来像是获取值:

public class ViewerController:Controller
{

   public ActionResult view(string filepath,string filename) //datatype may vary according to the model
    {
          //your action logic

     }

}