Joe Pelish
asked on
Getting dupes in Index View
I am a newbie to C# and have inherited a web app that I am now solely responsible for fixing and enhancing. I just created a Controller and a view via the VS wizard "MVC 5 Controller with views, using Entity Framework". I am using the default code that VS generated.
I also noticed that the record still comes up even if the ID is the same one as in the SQL View.
Any help would be greatly appreciated!
I have tried to start over and build everything a second time.
This is the controller.
public ActionResult Index(int? id)
{
This is the index.cshtml code
1050001010 10000.00 7/25/2015 12:00:00 AM
1050001010 10000.00 7/25/2015 12:00:00 AM
1050001010 10000.00 7/25/2015 12:00:00 AM
My SQL View returns the three different records as expected. In the view I have both primary keys from both tables I have join in the sql view. The code just calls the view, I did not import the view into VS 2019.
Here is a log output that the original programmer captures.
I get this error in a log.
SOURCE:System.Core TRACE: at System.Linq.Enumerable.Sin gleOrDefau lt[TSource ](IEnumera ble1 source) at System.Data.Entity.Core.Ob jects.ELin q.ObjectQu eryProvide r.b__2[TRe sult](IEnu merable1 sequence) at System.Data.Entity.Core.Ob jects.ELin q.ObjectQu eryProvide r.ExecuteS ingle[TRes ult](IEnum erable`1 query, Expression queryRoot) at System.Data.Entity.Core.Ob jects.ELin q.ObjectQu eryProvide r.System.L inq.IQuery Provider.E xecute[TRe sult](Expr ession expression)
Any help would be greatly appreciated. Thanks
I also noticed that the record still comes up even if the ID is the same one as in the SQL View.
Any help would be greatly appreciated!
I have tried to start over and build everything a second time.
This is the controller.
public ActionResult Index(int? id)
{
if (id == null) { return new HttpStatusCodeResult(HttpS tatusCode. BadRequest ); }
ViewBag.ID = id;
return View(db.JD.Where(x=>x.ID ==id).ToList());
}ViewBag.ID = id;
return View(db.JD.Where(x=>x.ID ==id).ToList());
This is the index.cshtml code
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.JudgmentID)
</td>
<td>
@Html.DisplayFor(modelItem => item.LoanID)
</td>
<td>
@Html.DisplayFor(modelItem => item.JudgmentAmount)
</td>
<td>
@Html.DisplayFor(modelItem => item.JudgmentDate)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details" , "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
}
This is what is displayed. There are actually 3 different records it should display.{
<tr>
<td>
@Html.DisplayFor(modelItem
</td>
<td>
@Html.DisplayFor(modelItem
</td>
<td>
@Html.DisplayFor(modelItem
</td>
<td>
@Html.DisplayFor(modelItem
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details"
@Html.ActionLink("Delete",
</td>
</tr>
}
1050001010 10000.00 7/25/2015 12:00:00 AM
1050001010 10000.00 7/25/2015 12:00:00 AM
1050001010 10000.00 7/25/2015 12:00:00 AM
My SQL View returns the three different records as expected. In the view I have both primary keys from both tables I have join in the sql view. The code just calls the view, I did not import the view into VS 2019.
Here is a log output that the original programmer captures.
I get this error in a log.
SOURCE:System.Core TRACE: at System.Linq.Enumerable.Sin
Any help would be greatly appreciated. Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.