Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'IEnumerable<getCustomerByCustomerId_Result>' does not contain a definition for 'CustomerId' and no extension method 'CustomerId' accepting a first argument of type 'IEnumerable<getCustomerByCustomerId_Result>' could be found (are you missing a using directive or an assembly reference?)
Source Error:
|
Line 17: @Html.ValidationSummary(true, "", new { @class = "text-danger" })
Line 18: <div class="form-group">
Line 19: @Html.LabelFor(model => model.CustomerId, htmlAttributes: new { @class = "control-label col-md-2" })
Line 10: <div class="col-md-10">
Line 21: @Html.EditorFor(model => model.CustomerId, new { htmlAttributes = new { @class = "form-control" } })
|
Class
namespace MvcMusicStore.Models
{
using System;
public partial class getCustomerByCustomerId_Result
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string Country { get; set; }
}
}
Controllers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcMusicStore.Models;
namespace MvcMusicStore.Controllers
{
public class StoreController : Controller
{
MVCMUSICSTOREEntities entities = new MVCMUSICSTOREEntities();
// GET: Store
public ActionResult Index()
{
return View();
}
public ActionResult Edit(int? CustomerId)
{
List<getCustomerByCustomerId_Result> customers = entities.getCustomerByCustomerId(2).ToList();
return View(customers);
}
}
}
Looks like Views having problem - System.Collections.Generic.IEnumerable' does not contain a definition for 'CustomerId'
Views
@model IEnumerable<MvcMusicStore.Models.getCustomerByCustomerId_Result>
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>getCustomerByCustomerId_Result</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.CustomerId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CustomerId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CustomerId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Country, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Country, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Country, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
How to rectify the Views ?