操纵模型然后在视图中反映它

时间:2013-01-14 11:26:43

标签: asp.net-mvc-4

我有LogoutModel个属性。我希望我的HomeController更改此值,然后View显示此值,但它似乎不起作用。显示退出视图时,它显示:'Goodbye Html.LabelFor(m => m.PreviouslyLoggedInUsername)'

LogoutModel:

public class LogoutModel
        {
            public string PreviouslyLoggedInUsername { get; set; }
        }

HomeController中:

        public ActionResult Logout(HomeModels.LogoutModel model)
        {
            model.PreviouslyLoggedInUsername = previousLoggedIn;
            return View(model);
        }

查看:

@using Ecommerce.Models
@model HomeModels.LogoutModel
@{
    ViewBag.Title = "Logout";
    Layout = "~/Views/Shared/Master.cshtml";
}

<h2>You have been logged out.</h2>

@using (Html.BeginForm())
{
    <table>
        <tr>
            <td>
                <label>Goodbye </label>
                Html.LabelFor(m => m.PreviouslyLoggedInUsername)
            </td>
        </tr>
    </table>

}

1 个答案:

答案 0 :(得分:0)

您需要在@

之前放置Html.LabelFor...符号
<table>
    <tr>
        <td>
            <label>Goodbye </label>
            @Html.LabelFor(m => m.PreviouslyLoggedInUsername)
        </td>
    </tr>
</table>

供参考,这是Razor syntax quick guide.