-3
我用ViewBag創建了我的網站,但是從Java我知道有getter和setter。我知道如何創建這個getter和setter,但我不知道如何獲得CSHTML文件中的值? 我試了一下:MVC中的C#Getter Setter
<p>Message1: @Model1.test</p>
<p>Message2: @Html.DisplayFor(model => model.test)</p>
感謝您的幫助
控制器:
public ActionResult Index()
{
Model1 model = new Model1();
model.test = "Hallo Test!";
return View();
}
型號:
public string test { get; set; }
[Getter和.NET中二傳手聲明]的可能重複使用模型( http://stackoverflow.com/questions/17881091/getter-and-setter-declaration-in-net) –
這段代碼做了什麼或不做什麼?請閱讀[問]。 – CodeCaster
顯示您的控制器方法。你想設置變量的位置以及你想要獲取的位置? –