I don't have duplicate id and ID fields, but I do have interestRate1 and InterestRate1 fileds.
The thing I don't understand is why that would be causing this probelm because I'm certain that the id field has a value of '2' and the ONLY record in the database has a value of '1'.
I don't have duplicate id and ID fields, but I do have interestRate1 and InterestRate1 fileds.
I was taking ID field as an example, yes, you need to modify these fields to be unique irrespective of casing.
eric2820
The thing I don't understand is why that would be causing this probelm because I'm certain that the id field has a value of '2' and the ONLY record in the database has a value of '1'.
Its not about DB or values, its the way DefaultModelBinder works.
eric2820
Contributor
2777 Points
1161 Posts
An item with the same key has already been added.
Nov 25, 2012 07:39 PM|LINK
This is the View for the data that is generating this error:
@model My_MSI.Net.Models.Entities.BankData
@{
ViewBag.Title = "Admin BackOffice | Enter Bank Info";
Layout = "~/Views/Shared/_BackOffice_Layout.cshtml";
}
<h2>My-MSI.Net | Admin Back Office | Enter Bank Info</h2>
@using ( Html.BeginForm() )
{
<table>
<tr>
<td style="text-align: center" colspan="2">
@Html.ValidationSummary()
</td>
</tr>
<tr>
<td style="text-align: right">
Bank Name:
</td>
<td style="text-align: left">
@Html.EditorFor( m => Model.bankName )
</td>
</tr>
<tr>
<td style="text-align: right">
As Of Date:
</td>
<td style="text-align: left">
@Html.EditorFor( m => Model.asOfDate )
</td>
</tr>
<tr>
<td style="text-align: right">
Savings Interest Rate:
</td>
<td style="text-align: left">
@Html.EditorFor( m => Model.interestRate1 )
</td>
</tr>
<tr>
<td style="text-align: right">
CD Interest Rate:
</td>
<td style="text-align: left">
@Html.EditorFor( m => Model.interestRate2 )
</td>
</tr>
<tr>
<td style="text-align: right">
CD Term:
</td>
<td style="text-align: left">
@Html.EditorFor( m => Model.cdTerm )
</td>
</tr>
<tr>
<td style="text-align: right">
Savings Url:
</td>
<td style="text-align: left">
@Html.EditorFor( m => Model.url1
</td>
</tr>
<tr>
<td style="text-align: right">
CD Url:
</td>
<td style="text-align: left">
@Html.EditorFor( m => Model.url2 )
</td>
</tr>
<tr>
<td style="text-align: center" colspan="2">
@Html.Hidden("id", Model.GetNextId().ToString() )
<input type="submit" id="submit" value="Submit" />
</td>
</tr>
</table>
}
I have verifoed that the Hiddent field has a value of '2'. And currently that the only id in the database is '1'.
What I do not understand is why I keep getting this error even with breakpoints set in the Controller!
Any suggestions?
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
ignatandrei
All-Star
134511 Points
21576 Posts
Moderator
MVP
Re: An item with the same key has already been added.
Nov 26, 2012 03:09 AM|LINK
stack trace, please.
eric2820
Contributor
2777 Points
1161 Posts
Re: An item with the same key has already been added.
Nov 26, 2012 09:02 AM|LINK
Stack Trace:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
ignatandrei
All-Star
134511 Points
21576 Posts
Moderator
MVP
Re: An item with the same key has already been added.
Nov 26, 2012 10:49 AM|LINK
very strange... all MVC error - no link with database id1 or 2. Could you reproduce on a sample project, no database involved?
CPrakash82
All-Star
18154 Points
2831 Posts
Re: An item with the same key has already been added.
Nov 26, 2012 10:58 AM|LINK
Do you have model property with the same name with different casing? Model Binder doesn't support that.
Ex. -
public int ID {get;set;}
public int id {get;set;}
If you have similar scenario, it will not work. Please check your model and change it accordingly.
eric2820
Contributor
2777 Points
1161 Posts
Re: An item with the same key has already been added.
Nov 26, 2012 12:38 PM|LINK
I don't have duplicate id and ID fields, but I do have interestRate1 and InterestRate1 fileds.
The thing I don't understand is why that would be causing this probelm because I'm certain that the id field has a value of '2' and the ONLY record in the database has a value of '1'.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
CPrakash82
All-Star
18154 Points
2831 Posts
Re: An item with the same key has already been added.
Nov 26, 2012 12:43 PM|LINK
I was taking ID field as an example, yes, you need to modify these fields to be unique irrespective of casing.
Its not about DB or values, its the way DefaultModelBinder works.