【发布时间】:2017-02-01 15:01:33
【问题描述】:
似乎在 ASP.NET Core 中,asp-* 属性中的值(例如asp-for)取自模型之前的请求负载。示例:
发布此值:
MyProperty="User entered value."
到这个动作:
[HttpPost]
public IActionResult Foo(MyModel m)
{
m.MyProperty = "Change it to this!";
return View();
}
或此操作
[HttpPost]
public IActionResult Foo(MyModel m)
{
m.MyProperty = "Change it to this!";
return View(m);
}
视图呈现这个:
<input asp-for="MyProperty" />
表单输入中的值是User entered value.,而不是Change it to this!。
首先,我很惊讶我们不需要将模型传递给视图并且它可以工作。其次,令我震惊的是请求有效负载优先于传递到视图中的模型。任何人都知道这个设计决定的基本原理是什么?使用asp-for 属性时有没有办法覆盖用户输入的值?
【问题讨论】:
标签: asp.net asp.net-core asp.net-core-mvc .net-core asp.net-core-1.0