简体   繁体   English

无法引用MVC视图中的所有模型对象

[英]Unable to reference all Model objects in MVC View

I have an odd problem whereby the model in my vbhtml file will correctly reference and bring up the model's attributes for 1 item but not for another. 我有一个奇怪的问题,即我的vbhtml文件中的模型将正确引用并显示出一项的模型属性,而不是另一项。 FYI, The page is added as a partial page, connected to another vbhtml page. 仅供参考,该页面被添加为部分页面,并连接到另一个vbhtml页面。

My page is structured such that I want to list a number of people (beneficiaries), below each question (question text). 我的页面结构合理,因此我想在每个问题(问题文本)下方列出一些人(受益人)。

I am referencing my Model type using the syntax: @ModelType RHEAL_START.QuestionWithAnswers, so this should automatically allow the model items to be declared when instantiated. 我使用以下语法来引用我的模型类型:@ModelType RHEAL_START.QuestionWithAnswers,因此这应允许实例化时自动声明模型项。

The @ModelType declaration correctly allows the referencing of the 2nd model field (Model.benAnswers) but not the first one I have declared (Model.questionText). @ModelType声明正确地允许引用第二个模型字段(Model.benAnswers),但不允许引用我已声明的第一个模型(Model.questionText)。

Both items are part of the same model and, I have tried moving the declarations above and below the and headers but, this did not bring up an IntelliSense for the Model.questionText. 这两个项目都是同一模型的一部分,并且我尝试将声明移到and标题的上方和下方,但是,这并没有为Model.questionText带来IntelliSense。

I looked at the following post and tried addding in a reference to the Layout file but alas, this did not bring up an IntelliSense either. 我查看了以下文章,并尝试添加对Layout文件的引用,但是,这也没有带来IntelliSense。 MVC3 - render view that is not a method in a controller MVC3-控制器中不是方法的渲染视图

See the code below. 请参见下面的代码。 Can anyone suggest where I'm going wrong and what else I can try? 谁能建议我要去哪里错了,我还能尝试什么? If you need more information, please let me know. 如果您需要更多信息,请告诉我。

@ModelType RHEAL_START.QuestionWithAnswers
@Code
    Layout = "~/Views/MedicalQuestions/MedicalQuestions.vbhtml"
End Code
    <div id="questionPanel">
        @Code 
            Dim qAndARef As Integer = 0
        End Code

            <!-- Show question text and number -->
            <h1><a href="#">Model.questionText</a></h1>

            <table>

                <tr>
                    <td style="font-weight: bold">
                        Beneficiary </td>
                    <td style="font-weight: bold">
                        Yes/No </td>
                    <td style="font-weight: bold">
                        Details </td>
                </tr>

                <!-- !!Iterating over each beneficiary for Medical Question -->

                @For Each benanswer As RHEAL_START.BeneficiaryAnswer In Model.benAnswers

                Html.Partial("../MedicalQuestions/BeneficiaryAnswerPartial", benanswer)

                Next
            </table>


        @*@Html.ValidationSummary()*@

    </div>

@Section Scripts
    @Scripts.Render("~/Scripts/RHEAL/YesNoDropDownValidation.js")
End Section

我对Razor的VB语法不太熟悉,但是好像您在@Model.questionText前面缺少@符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM