【发布时间】:2020-01-24 13:27:55
【问题描述】:
我在编辑数据的地方拥有剃刀视图。
我的课程是这样的:
public class A
{
public string Value1 { get; set; }
public int Value2 { get; set; }
public A()
{
Value1 = "First";
Value2 = 2;
}
}
public class B : A
{
public int Value3 { get; set; }
public new CustomClass Value1 { get; set; }
public B()
{
Value3 = 3;
Value2 = new CustomClass();
}
}
现在当我打电话给我的Razor View 时,我会这样称呼它:
public IActionResult Edit()
{
return View(new B());
}
在我的cshtml 代码中,我的设置如下:
@using (Html.BeginForm("Apply", "MyController", FormMethod.Post))
{
@Html.HiddenFor(x => x.Value1);
<label>Change value 3</label>
@Html.EditorFor(x => x.Value3);
<button class="button1">Apply!</button>
}
现在由于某种原因,当我应用更改时,它们确实应用了,但 Value1 参数错误。
我检查了代码的入口,我看到Value1 具有良好的价值,检查了/MyController/Apply 代码,它的值为 null。
当我在cshtml 中设置断点以查看哪个值具有@HiddenFor(x => x.Value1) 时,我看到了一些奇怪的东西,就是这个(图像中的标记属性在上面的代码中表示为Value2):
如您所见,由于某种原因,razor 具有两种属性,但一种具有null(他在内部视图中)和一种具有良好值的属性。
我能做什么?
【问题讨论】:
标签: c# asp.net asp.net-core razor razor-pages