Bind 三個關鍵字 Exclude / Include / Prefix
對於這篇文章我保持疑問
大概是後續的.Net MVC有做改版改掉了這些問題吧?
有三個Bind的關鍵字
1.Exclude
2.Include
3.Prefix
Model
public class TestViewModel : TestModel {
public int TestIdView { get; set; }
public string TestStringView { get; set; }
}
public class TestModel {
public int TestId { get; set; }
public string TestString { get; set; }
}
Controller
public ActionResult About() {
TestViewModel tm = new TestViewModel();
tm.TestIdView = 123;
tm.TestStringView = "456";
ViewBag.Message = "Your application description page.";
return View(tm);
}
View
<p>@Html.TextBoxFor(m => m.TestIdView)</p>
<p>@Html.TextBoxFor(m => m.TestStringView)</p>
<div>
<label>
id:
</label>
@Html.DisplayFor(m => m.TestIdView)
<label>
string:
</label>
@Html.DisplayFor(m => m.TestStringView)
</div>
顯示:
我這邊依照 這篇 文章的作法 我依舊能輸出數字。
So 其實我也不太確定為何要儲存這篇
參考:
https://dotblogs.com.tw/SteveLiu/2020/01/13/130941
留言
張貼留言