-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
显示您的控制器方法。你想设置变量的位置以及你想要获取的位置? –