I created the TestDisplay View because the Test View didn't display the model that came back from the
Controller. Of course the TestDisplay has the same issue that the Test View had. It fails to display the second and third items!
... and check that data.encMember and data.memberDecrypted have values in them. It seems like the problem is the assignment lines for those two properties.
I have a breakpoint set in the controller and yes they do have values. The encMember is a hash or encription of the password and the decryptedMember is either null or has the decrypted password in it (depending on which tests I'm performing in the controller.
eric2820
Contributor
2777 Points
1161 Posts
View not updateing
Dec 12, 2012 09:18 PM|LINK
I have a view with three fields only one of which is required.
The user puts a value in the that one filed.
It goes back to the controller.
The controler populates one or two of the other fields and returns the data to the view.
The problem is that when the View refreshes those two text boxes are still empty.
This is just a test page, but I would still like to get it working!
Any suggestions??
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: View not updateing
Dec 13, 2012 12:20 AM|LINK
Here is the Model:
public class Test
{
private string _password2;
[Required( ErrorMessage="Password is required.", AllowEmptyStrings=false )]
public string password { get; set; }
public string memberDecrypted
{
get { return _password2; }
set { _password2 = value; }
}
public string encMember { get; set; }
}
And here is the controller method:
[HttpGet]
public ActionResult Test()
{
Test test = new Test();
return View( test );
}
[HttpPost]
public ActionResult Test( Test data )
{
//data.encMember = Utility.Encode( data.password );
data.encMember = Utility.Encrypt( data.password );
data.memberDecrypted = Utility.Decrypt( data.encMember );
return View( "TestDisplay", data );
}
And here are the two Views that I'm using:
Test View:
@model My_MSI.Net.Models.Entities.Test
@{
ViewBag.Title = "Test";
Layout = "~/Views/Shared/_BackOffice_Layout.cshtml";
}
<h2>Admin | Back Office | Test</h2>
@using ( Html.BeginForm() )
{
<table style="width: 75%">
<tr>
<td colspan="2" style="text-align:center">
@Html.ValidationSummary()
</td>
</tr>
<tr>
<td style="text-align:right">
@Html.Label( "Password: " )
</td>
<td style="text-align:left">
@Html.EditorFor( m => m.password )
</td>
</tr>
<tr>
<td style="text-align:right">
@Html.Label( "Enc Member: " )
</td>
<td style="text-align:left">
@Html.TextBoxFor( m => m.encMember, new { style="width:100%" } )
</td>
</tr>
<tr>
<td style="text-align:right">
@Html.Label( "Decrypted Member: " )
</td>
<td style="text-align:left">
@Html.TextBoxFor( m => m.memberDecrypted )
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit" />
</td>
</tr>
</table>
}
And here is the TestDisplay View:
@model My_MSI.Net.Models.Entities.Test
@{
ViewBag.Title = "Test Display";
Layout = "~/Views/Shared/_BackOffice_Layout.cshtml";
}
<h2> Admin | Back Office | Test Display</h2>
<table style="width:95%">
<tr>
<td style="text-align: right">
@Html.Label( "Member: " )
</td>
<td style="text-align: left">
@Html.TextBoxFor( m => m.password )
</td>
</tr>
<tr>
<td style="text-align: right">
@Html.Label( "encMember: " )
</td>
<td style="text-align: left">
@Html.TextBoxFor( m => m.encMember, new { style = "width:100%" } )
</tr>
<tr>
<td style="text-align: right">
@Html.Label( "memberDecrupted: " )
</td>
<td style="text-align: left">
@Html.TextBoxFor( m => m.memberDecrypted )
</td>
</tr>
</table>
I created the TestDisplay View because the Test View didn't display the model that came back from the Controller. Of course the TestDisplay has the same issue that the Test View had. It fails to display the second and third items!
What is going wrong here???
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
soulwind28
Member
88 Points
19 Posts
Re: View not updateing
Dec 13, 2012 01:24 AM|LINK
I would put a breakpoint on the line
... and check that data.encMember and data.memberDecrypted have values in them. It seems like the problem is the assignment lines for those two properties.
ignatandrei
All-Star
134521 Points
21576 Posts
Moderator
MVP
Re: View not updateing
Dec 13, 2012 06:34 AM|LINK
ModelState.RemoveKey("encMember");
ModelState.Remove("encMember");
data.encMember = Utility.Encrypt( data.password );
eric2820
Contributor
2777 Points
1161 Posts
Re: View not updateing
Dec 13, 2012 08:52 AM|LINK
I have a breakpoint set in the controller and yes they do have values. The encMember is a hash or encription of the password and the decryptedMember is either null or has the decrypted password in it (depending on which tests I'm performing in the controller.
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: View not updateing
Dec 13, 2012 08:58 AM|LINK
ModelState.RemoveKey doesn't exist, but ModelState.Remove( "encMember" ) worked.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
ignatandrei
All-Star
134521 Points
21576 Posts
Moderator
MVP
Re: View not updateing
Dec 13, 2012 10:22 AM|LINK
syntax error, sorry...