创建并将模型从HTML传递给Controller

时间:2014-11-25 13:46:36

标签: html asp.net-mvc asp.net-mvc-5

我有以下

LegacyController

public ActionResult Index(Intranet.Models.LegacyModel legacy)
{
    return View(legacy);
}

LegacyView

@model Intranet.Models.LegacyModel
@{
    ViewBag.Title = @Model.PageTitle;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@File.ReadAllText(Server.MapPath(Model.URL));

LegacyModel

public class LegacyModel
{
    public string PageTitle { get; set; }
    public string URL { get; set; }
}

在_layout页面中我有菜单。当用户在cshtml页面中单击我想要的链接时,使用正确的属性创建LegacyModel对象并将其传递给控制器​​,以便显示视图。

1 个答案:

答案 0 :(得分:0)

使用@ Html.Actionlink

计算出来
@Html.ActionLink("Dec. 2014", "Index", "Legacy", 
new { PageTitle = "Newsletter Dec. 2014", URL = "~/Content/Documents/Newsletter/December2012/MainPage.htm" }, null)