1

Yet another compile error for me:

Error 1 'Model' conflicts with the declaration 'System.Web.Mvc.ViewUserControl.Model' c:\Users\Kevin\Documents\Visual Studio 2010\Projects\HandiGamer\HandiGamer\Views\Shared\EditorTemplates\AdminGameReviewViewModel.ascx 10 51 HandiGamer.WebUI

I'm trying to use a partial view to handle both Create and Edit functionality. So, my Create view is:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<HandiGamer.WebUI.ViewModels.AdminGameReviewViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Create New Review
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Create New Review</h2>

    <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>

        <fieldset>
            <legend>Create New Review</legend>
            <%: Html.EditorForModel() %>

            <p>
                <input type="submit" value="Save" />
            </p>
        </fieldset>

     <% } %>

    <div>
        <%: Html.ActionLink("Back to Menu", "Index") %>
    </div>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="CSSandJavaScript" runat="server">
</asp:Content>

And the partial view is:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<HandiGamer.WebUI.ViewModels.AdminGameReviewViewModel>" %>

<p>
    <%: Html.Label("Game Title") %>
    <%: Html.TextBoxFor(Model => Model.GameData.GameTitle) %>
    <%: Html.ValidationMessageFor(Model => Model.GameData.GameTitle) %>
</p>
<p>
    <%: Html.LabelFor(Model => Model.GameData.Genre) %>
    <%: Html.DropDownList("Genre", new SelectList(Model.AllGenres, "GenreID", "Name", Model.GameData.GenreID)) %>
</p>
<p>
    <%: Html.Label("Platforms") %><br />
    <% for (int i = 0; i < Model.AllPlatforms.Count(); ++i) { %>
       <%: Model.AllPlatforms[i].Platform.Name %> <%: Html.CheckBoxFor(plat => plat.AllPlatforms[i].IsSelected)%><br />
    <% } %>
</p>
<p>
    <%: Html.Label("Review Title") %>
    <%: Html.TextBoxFor(model => model.GameData.Content.Title) %>
</p>
<p>
    <%: Html.Label("Review") %>
    <%: Html.TextAreaFor(model => model.GameData.Content.Text) %>
</p>
<p>
    <%: Html.Label("Review Score") %>
    <%: Html.DropDownList("Score", new SelectList(new int[] {1, 2, 3, 4, 5}, "ReviewScore")) %>
</p>
<p>
    <%: Html.LabelFor(model => model.GameData.Pros) %><br />
    <%: Html.TextBox("Pros[]") %><br />
    <%: Html.TextBox("Pros[]") %><br />
    <%: Html.TextBox("Pros[]") %><br />
    <%: Html.TextBox("Pros[]") %><br />
    <%: Html.TextBox("Pros[]") %>
</p>

The line in question is the one that attempts to create the first DropDownList, specifically when I write Model.AllGeneres. That invocation of Model is what's throwing the error. It's confusing since none of the other attempts to access Model trigger an error.

0

1 Answer 1

1

The first few html helpers in your partial are using the capital 'Model' instead of lowercase 'model' for the lambda parameter. You have

<%: Html.TextBoxFor(Model => Model.GameData.GameTitle) %>

But it should be

<%: Html.TextBoxFor(model => model.GameData.GameTitle) %>
Sign up to request clarification or add additional context in comments.

1 Comment

Yup, you're right. What a brain fart that was on my part. Kept looking at it wrong. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.