does not contain a public definition for 'GetEnumerator' in MVC4

Posted by Mandlaa under ASP.NET MVC on 9/30/2013 | Points: 10 | Views : 12455 | Status : [Member] | Replies : 5
VIEW:

@model Hoda.Models.REVIEW
@using Hoda.Models
@using System.Collections.Generic;

@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Create</h2>
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.Email)
<br />
@Html.DisplayFor(modelItem => item.Hondareviews)
}
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)

<fieldset class="form-horizontal">
<legend>REVIEW</legend>
<div class="control-group">
@Html.LabelFor(model => model.Email, new { @class = "control-label" })
<div class="controls">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email, null, new { @class = "help-inline" })
</div>
</div>
<div class="control-group">
@Html.LabelFor(model => model.Hondareviews, new { @class = "control-label" })
<div class="controls">
@Html.EditorFor(model => model.Hondareviews)
@Html.ValidationMessageFor(model => model.Hondareviews, null, new { @class = "help-inline" })
</div>
</div>

<div class="form-actions no-color">
<input type="submit" value="Create" class="btn" />
</div>
</fieldset>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

Controller:

public ActionResult Create(REVIEW r)
{

ProductDataDataContext db = new ProductDataDataContext();
db.REVIEWs.InsertOnSubmit(r);
db.SubmitChanges();
return RedirectToAction("Create");

}

This is my code for insert data using Linq,

After inserting that data will be display same page,

I am getting error like this
http://s17.postimg.org/a17gv36e7/image.png




Responses

Posted by: Bandi on: 9/30/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
refer this link
http://www.codeproject.com/Questions/572274/ToplusShowplusListplusinplusMvc


support links:
http://social.msdn.microsoft.com/Forums/en-US/ec725b6d-a7ec-4135-98bf-205c0a6f12fa/error-when-use-foreach-statement
http://www.experts-exchange.com/Microsoft/Development/Q_27897395.html

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/30/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
The reasons and fixes for the above error:
http://forums.asp.net/t/1329430.aspx
http://stackoverflow.com/questions/16857503/mvc-4-generate-list-in-view
http://stackoverflow.com/questions/7009313/compiler-error-in-mvc-music-store

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/30/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
May be this?
@model IEnumerable<Hoda.Models.REVIEW>


Reference:
http://forums.asp.net/t/1904445.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/30/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Mandlaa,

Just replace @model Hoda.Models.REVIEW with the below one.

@model IEnumerable<Hoda.Models.REVIEW>


Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 9/30/2013 [Member] Starter | Points: 25

Up
0
Down
@model Hoda.Models.REVIEW replacing this one getting the following error

CS1061: 'System.Collections.Generic.IEnumerable<Hoda.Models.REVIEW>' does not contain a definition for 'Email' and no extension method 'Email' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Hoda.Models.REVIEW>' could be found (are you missing a using directive or an assembly reference?)

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response