我正在使用RazorGenerator
将视图嵌入到共享 DLL 中。我有一个HiddenFor
正在生成一个无效name
属性和一个缺少的id
属性。
我有一个视图模型:
public class InsuredPartiesViewModel
{
public List<OrganisationViewModel> OrganisationWithBranches { get; set; }
...
public class OrganisationViewModel : IInsuredPartyViewModel
{
public bool CanQueryIVTRForBranches { get; set; }
...
在 Razor 视图中,我使用 a@helper
来迭代:
@helper RenderHiddenFieldsForInsuredParty(int insuredPartyIndex, bool branchesAreVisible)
{
@Html.HiddenFor(x => Model.OrganisationWithBranches[insuredPartyIndex].CanQueryIVTRForBranches)
...
输出是:
<input data-val="true" data-val-required="The HasQueryIVTRForBranches field is required." name="<>4__this.Model.OrganisationWithBranches[0].HasQueryIVTRForBranches" type="hidden" value="False" />
预期的输出是(我可以从旧代码分支中看到):
<input data-val="true" data-val-required="The HasQueryIVTRForBranches field is required." name="<>4__this.Model.OrganisationWithBranches[0].HasQueryIVTRForBranches" type="hidden" value="False" />
id
缺少name
属性,并且看起来像 Razor 的解析器的属性<>4__this.Model.OrganisationWithBranches[0].HasQueryIVTRForBranches
卡住了。
你以前见过这个吗?如何调试 Razor 输出?
VS2013 和 VS2015、ASP.NET MVC 5 中的行为相同。进入视图的数据是正确的。
更新
辅助方法NameFor
也会产生错误结果。
@Html.NameFor(x => Model.OrganisationWithBranches[insuredPartyIndex].CanQueryIVTRForBranches)