Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6599575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:30:33+00:00 2026-05-25T18:30:33+00:00

I have a strongly typed view, Edit, with a model named OrderModel. In this

  • 0

I have a strongly typed view, Edit, with a model named OrderModel. In this view, I am using a strongly typed partial view that has a model named OrderTypeModel. The partial view, _OrderTypeAutoComplete, that contains a jqueryui autocomplete textbox. If I render the view with this code,

public ActionResult Edit(){
    return View();
}

My Edit view contains the following Razor markup

<div class="editor-field">
    @Html.Partial("_OrderTypeAutoComplete")
    @Html.HiddenFor(model => model.OrderTypeID)
    @Html.ValidationMessageFor(m => m.OrderTypeID)
</div>

My Partial view contains this razor markup

@{
    Layout = null;
}
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
@Html.AutoCompleteFor(model => model.OrderTypeID, x =>  x.OrderType, "Items","Orders")

When I render this, all is great and my autocomplete works great (using an auto-complete extension). Anyway, I needed to initialize something in my initial OrderModel, so I changed the code in my controller to this.

public ActionResult Edit(){
    return View(OrderService.GetInitializedOrderModel()); //returns a new OrderModel
}

Now when I render the view, I get the exception:
The model item passed into the dictionary is of type ‘Testing.Models.OrderModel’, but this dictionary requires a model item of type ‘Testing.Models.OrderTypeModel’.

on this line in my view
@Html.Partial(“_OrderTypeAutoComplete”)

It seems the Razor engine will create the OrderModel for the view and the OrderTypeModel for the partial view fine when I haven’t supplied the OrderModel. This will give the same results.

public ActionResult Edit(){
    return View(new OrderModel())
}

I’m new to MVC so I’m not sure what’s going on here. I’m simply trying to provide some simple dropdown values for my view in the OrderModel model that are small enough that I don’t require a jquery postback to get. That’s the values I’m initialing in my model for the Http Get on my Edit action.

Any help would be appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:30:34+00:00Added an answer on May 25, 2026 at 6:30 pm

    The class definitions for your model classes are missing from the example so I can’t tell exactly what is going on, but…

    The @Html.Partial() method has a few overloads:

    @Html.Partial(string)
    @Html.Partial(string, Object)
    @Html.Partial(string, ViewDataDictionary)
    @Html.Partial(string, Object, ViewDataDictionary)
    

    The first three overloads are all just “aliases” for the last one – when all’s said and done it is the last one that gets called.

    When you call the @Html.Partial(string) and do not pass a model value or ViewDataDictionary, ASP.NET MVC will just pass in the ViewDataDictionary for the current view (i.e. this.ViewData).

    I other words, a call to:

    @Html.Partial(string)
    

    Is essentially equivalent to:

    @Html.Partial(string, this.ViewData)
    

    … and in your case, this.ViewData is of type OrderModel, not OrderModelType.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strongly typed View that accepts a Customer model, this customer model
i have a strongly typed asp.net-mvc view and the Model has a . Links
Let's say I have an edit view that is strongly-typed to a table called
I have a strongly-typed view with a @model declaration: @model MyViewModel When using extension
I have a Search Edit view which is strongly typed to my Search model
I have a strongly typed view that is using a viewmodel I created. I
MVC newbie question re binders. Supposing I have two strongly typed partial actions that
I have a PartialView strongly typed to a view model <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<VATRateManager_MVC.Models.ViewModels.RateControlEditViewModel>
I have an edit object view. In this view are several DateTime? properties that
I'm working on a strongly-typed edit form for a MVC model that contains a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.