Answer the question
In order to leave comments, you need to log in
Error creating RenderPartialAsync, problem in controller?
There is an Index controller, in it I compare the data from the database with the modelview and my View takes the user's data and displays them. And accordingly below I will attach a PartialView
public class CustomerController : Controller
{
private ICustomerRepository _customerRepository;
public CustomerController(ICustomerRepository customerRepository)
{
_customerRepository = customerRepository;
}
[HttpGet]
public IActionResult Index()
{
IEnumerable<CustomerViewModel> customers =
_customerRepository.GetAllCustomers().Select(s => new
CustomerViewModel
{
CustomerId = s.CustomerId,
Name = s.Name,
Adress = s.Adress
});
return View("Index", customers);
}
[HttpGet]
public IActionResult Create()
{
return Redirect("Index");
}
}
@model IEnumerable<CustomerViewModel>
<h2>Create Customer</h2>
@{
await Html.RenderPartialAsync("Create");
}
<table class="table">
@Html.DisplayNameFor(model => model.Name)
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.Name)
}
</table>
@model CustomerViewModel
<div class="col-md-4">
<form asp-action="Create" asp-controller="Customer">
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input type="text" asp-for="Name" class="form-control" />
</div>
InvalidOperationException: The model item passed into the
ViewDataDictionary is of type 'System.Linq.Enumerable+SelectEnumerableIterator`
2[Store.DAL.Entity.Customer,Store.Web.ViewModels.CustomerViewModel]', but this
ViewDataDictionary instance requires a model item of type 'Store.Web.ViewModels.
CustomerViewModel
Store.Web.Pages.Customer.Views_Customer_Index.ExecuteAsync() in Index.cshtml - @{ ViewData["Title"] = "Customer"; } <h2>Create Customer</h2> @{ await Html.RenderPartialAsync("Create"); } <h2>Customers</h2> <table class="table"> <tr>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question