Hi
Error - The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MyApplication.Models.Product]', but this dictionary requires a model item of type 'MyApplication.Models.Product'.
JavaScript
@model IEnumerable
Index
Add New
@Html.DisplayNameFor(model => model.Id)
@Html.DisplayNameFor(model => model.Description)
Action
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.Id)
@Html.DisplayFor(modelItem => item.Description)
Edit
}
@using (Ajax.BeginForm("CreateEdit", "Product", new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "frmProduct" }))
{
×Close
Add New Product
@Html.Partial("_CreateEdit")
Cancel
Save Changes
}Thanks
Sachin SinghRank #66 · 26.2K reputationPosted Jun 15, 2021, 7:57 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Jun 15, 2021, 4:55 AM EDT
Ramco RamcoRank #462 · 5.4K reputationPosted Jun 15, 2021, 5:04 AM EDT
Location
*@
Sachin SinghRank #66 · 26.2K reputationPosted Jun 15, 2021, 5:28 AM EDT
class
="modal-title">Add New ProductRamco RamcoRank #462 · 5.4K reputationPosted Jun 15, 2021, 7:38 AM EDT
@model MyApplication.Models.Location
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>CreateEdittitle>
head>
<body>
@using (Html.BeginForm("CreateEdit", "Location", FormMethod.Post, new { @id = "locationFormId", @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<div class="" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×span>button>
<h4 Create New Location>h4>
div>
<div class="modal-body">
@*
Thanks
Location
*@
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.LabelFor(model => model.Id, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Id, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Id, "", new { @class = "text-danger" })
div>
div>
<div class="form-group">
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
div>
div>
div>
div>
div>
div>
}
body>
html>
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts