Good day,
I have a layout with a search box(with bootstrap and a self-made jquery typeahead).
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("EbanTabs", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
@Html.Partial("_TipoProyectoSearch") //<<my searchbox comes here
@*<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>*@
<ul class="nav navbar-nav">
@*<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>*@
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
</div>
you can see that my searchbox is a partialview that uses
//tipoproyectosearch partialview
@model MyProj.Models.Autocomplete
//start view
//...
//end view
This is the AutoComplete model
public class Autocomplete
{
public Guid Id { get; set; }
public string Name { get; set; }
}
My problem started when I created my home index view. I used a new model there
@model IEnumerable<MyProj.ViewModels.MyViewModel>
//here starts my view
//...
//end view
when I run my application I receive this error
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MyProj.ViewModels.MyViewViewModel]', but this dictionary requires a model item of type 'EbanTabs.Models.Autocomplete'.
The error message tells me that the model is not right, when the partialview is rendered.
How can I do to avoid this problem? I could see that some answers *MVC 5 Multiple Models in a Single View * that use a complex view model with two classes.
I think that this approach would add more complexity to my solution, because I would have to create many complex models when rendering data to my view.
Is there a better approach than the mentioned?
thanks in advance.