public
static
bool
Lookup( string
memberName, IDataProvider
db ) { var
ids = ( from
c in
db.Identity where
c.MemberName == memberName select
c ).AsEnumerable<Identity>(); foreach
(Identity
id in
ids) // there should only be one! { return
true; }
return
false; }
It seems that this code has a memory, in that if I test a memberName that does not exist or that does exist it works, but if I test a memberName that does not exist and go back (using the back button in IE) and test an existing memberName I get an incorrect
result!
Two questions:
1) Why is this happening?
2) What can I do to correct this issue?
Edit: Fiurther debugging shows that both times this method executes the ids object has no results. As if it's processing the exact same query twice instead of the new query for the new memberName value!
Edit #2: It seems that this is a MVC issue and not a DB Method isssue after all. Specifically, the form page has a single edit box on it, and when I enter a memberName of '1234' which is not in the database the method returns the correct value. But If I
click on the link that brings this page up again, the MemberName field still has '1234' in it and when I change it to 'Admin' (which is in the database) the DB method still sees the memberName as '1234'!
Two questions:
1) Why is this happening, and
2) What can be done to correct this MVC issue?
For the record, the View looks like this:
@model My_MSI.Net.Models.Entities.JoinData @{
ViewBag.Title = "My-MSI.Net - Join"; }
<h2>My-MSI.Net
- Join</h2> <p>Thank-you
for the decision to join all of us here at <strong>My-MSI.NET</strong>.</p> <p>The
first thing you need to decide on is your <b>Member
Name</b>
which will appear in the url of your <b>referral
site</b>.</p> @using(Html.BeginForm()) {
<tablewidth="75%"style="
table-layout:fixed;
text-align:
left;"> <tr> <tdalign="center"colspan="3"> @Html.ValidationSummary()
</td> </tr> <tr> <tdstyle="width:25%"></td> <tdalign="left"colspan="2"nowrap> @Model.Message
</td> <tdstyle="width:25%"></td> </tr> <tr> <tdalign="right"style="width:50%"> Member Name::
</td> <tdalign="left"> @Html.TextBox( "NewMemberName") </td> <td></td> </tr> </table> @Html.Hidden( "StateStep",
1) <inputtype="submit",
value="Submit"/> }
And by the way, changing the @Html.TextBox("NewMemberName") to @Html.EditorFor( x => @Model.NewMemberName ) did not solve this issue!
Okay, my bad, the NewMemberName field was being stored in a cookie. I changed that to a normal {get; set; } filed and left the Remove( "NewMemberName ) in place and it now works.
eric2820
Contributor
2777 Points
1161 Posts
DB Method returns the wrong result if called twice with what should be two different memberNames
Nov 17, 2012 02:18 PM|LINK
Now I have a different issue with this code:
public static bool Lookup( string memberName, IDataProvider db )
{
var ids = ( from c in db.Identity where c.MemberName == memberName select c ).AsEnumerable<Identity>();
foreach (Identity id in ids) // there should only be one!
{
return true;
}
return false;
}
It seems that this code has a memory, in that if I test a memberName that does not exist or that does exist it works, but if I test a memberName that does not exist and go back (using the back button in IE) and test an existing memberName I get an incorrect result!
Two questions:
1) Why is this happening?
2) What can I do to correct this issue?
Edit: Fiurther debugging shows that both times this method executes the ids object has no results. As if it's processing the exact same query twice instead of the new query for the new memberName value!
Edit #2: It seems that this is a MVC issue and not a DB Method isssue after all. Specifically, the form page has a single edit box on it, and when I enter a memberName of '1234' which is not in the database the method returns the correct value. But If I click on the link that brings this page up again, the MemberName field still has '1234' in it and when I change it to 'Admin' (which is in the database) the DB method still sees the memberName as '1234'!
Two questions:
1) Why is this happening, and
2) What can be done to correct this MVC issue?
For the record, the View looks like this:
@model My_MSI.Net.Models.Entities.JoinData
@{
ViewBag.Title = "My-MSI.Net - Join";
}
<h2>My-MSI.Net - Join</h2>
<p>Thank-you for the decision to join all of us here at <strong>My-MSI.NET</strong>.</p>
<p>The first thing you need to decide on is your <b>Member Name</b> which will appear in the url of your <b>referral site</b>.</p>
@using(Html.BeginForm())
{
<table width="75%" style=" table-layout:fixed; text-align: left;">
<tr>
<td align="center" colspan="3">
@Html.ValidationSummary()
</td>
</tr>
<tr>
<td style="width:25%"></td>
<td align="left" colspan="2" nowrap>
@Model.Message
</td>
<td style="width:25%"></td>
</tr>
<tr>
<td align="right" style="width:50%">
Member Name::
</td>
<td align="left">
@Html.TextBox( "NewMemberName")
</td>
<td></td>
</tr>
</table>
@Html.Hidden( "StateStep", 1)
<input type="submit", value="Submit" />
}
And by the way, changing the @Html.TextBox("NewMemberName") to @Html.EditorFor( x => @Model.NewMemberName ) did not solve this issue!
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
CPrakash82
All-Star
18290 Points
2844 Posts
Re: DB Method returns the wrong result if called twice with what should be two different memberNa...
Nov 17, 2012 04:35 PM|LINK
It is due to the way EditorFor and ModelState works. A detailed explanation is given at below thread.
http://forums.asp.net/t/1527149.aspx/1?A+Bug+EditorFor+and+DisplayFor+don+t+display+same+value+EditorFor+out+of+date
To resolve this you need to call out the ModelState.Remove([fieldName]) to remove the old value from ModelState before you return it to view.
In your case it will be - ModelState.Remove("NewMemberName ") just before return view.
eric2820
Contributor
2777 Points
1161 Posts
Re: DB Method returns the wrong result if called twice with what should be two different memberNa...
Nov 17, 2012 05:39 PM|LINK
Calling ModelState.Clear() did not resolve this problem. Any other ideas?
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
CPrakash82
All-Star
18290 Points
2844 Posts
Re: DB Method returns the wrong result if called twice with what should be two different memberNa...
Nov 17, 2012 06:07 PM|LINK
Try with .Remove and specific field name.
eric2820
Contributor
2777 Points
1161 Posts
Re: DB Method returns the wrong result if called twice with what should be two different memberNa...
Nov 17, 2012 06:48 PM|LINK
Followed your suggestion, but even calling ModelState.Remove( "fieldName" ) didn't allow this to work as it needs to.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
eric2820
Contributor
2777 Points
1161 Posts
Re: DB Method returns the wrong result if called twice with what should be two different memberNa...
Nov 17, 2012 07:08 PM|LINK
Okay, my bad, the NewMemberName field was being stored in a cookie. I changed that to a normal {get; set; } filed and left the Remove( "NewMemberName ) in place and it now works.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
eric2820
Contributor
2777 Points
1161 Posts
Re: DB Method returns the wrong result if called twice with what should be two different memberNa...
Nov 17, 2012 07:22 PM|LINK
Turns out that ModelState.Remove("filedName") wasn't needed at all since I was able to comment it out and the code still worked!
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.