1

我正在使用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="&lt;>4__this.Model.OrganisationWithBranches[0].HasQueryIVTRForBranches" type="hidden" value="False" />

预期的输出是(我可以从旧代码分支中看到):

<input data-val="true" data-val-required="The HasQueryIVTRForBranches field is required." name="&lt;>4__this.Model.OrganisationWithBranches[0].HasQueryIVTRForBranches" type="hidden" value="False" />

id缺少name属性,并且看起来像 Razor 的解析器的属性&lt;>4__this.Model.OrganisationWithBranches[0].HasQueryIVTRForBranches卡住了。

你以前见过这个吗?如何调试 Razor 输出?

VS2013 和 VS2015、ASP.NET MVC 5 中的行为相同。进入视图的数据是正确的。

更新

辅助方法NameFor也会产生错误结果。

@Html.NameFor(x => Model.OrganisationWithBranches[insuredPartyIndex].CanQueryIVTRForBranches)
4

0 回答 0