I have a controller named AccountsController in that i have action named public ActionResult ManageAccounts() and
[HttpPost]
Public ActionResult ManageAccounts(AccountsModel acc)
{ //Calling Fun from model
Return View();
}
In this Controller i get the value for Html.TextBoxFor(m=> m.name)
But what if i want this value on View (Accounts.aspx) also.
Actually i want to persist the value for this text box. I use this Text box for Filtering records of database. But when i click on Filter button i can access this value on Controller and i can get the filtered output also but the textbox becomes empty. I
want to persist the Text box value after filtering records too.
Between HttpGet and HttpPost this is automatically maintained . Please provide sample project for your ideas
It's only automatically maintained if the value is retrieved via model binding. It's the model binding process which puts the current value into ModelState, which is how we automatically round-trip things. If you don't somehow model bind "name", then the value
won't be preserved. You either need to model bind it, or set the value into ModelState by hand.
Marked as answer by ricka6 on Aug 20, 2010 08:20 PM
Public ActionResult ManageAccounts(AccountsModel acc)
sskulkarni
Return View();
sskulkarni
But what if i want this value on View (Accounts.aspx) also.
Where is Accounts.aspx come into action?
Is you need to maintain value in different requests?
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Since you are using a parameter which contains name. You don't neeed to do any thing else. TextBoxFor will be automatically bound to this value.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
sskulkarni
Member
31 Points
74 Posts
Getting value of Html.TextBoxFor(m => m.name)
Jul 22, 2010 05:33 AM|LINK
Hi All,
I am new to Asp.net MVC 2. I am unable to get value for Html.TextBoxFor(m = > m.name) in view. I can get this value in Controller.
How to get this value in view.
Please help.
HtmlHelper.TextBoxFor()
ignatandrei
All-Star
135142 Points
21676 Posts
Moderator
MVP
Re: Getting value of Html.TextBoxFor(m => m.name)
Jul 22, 2010 09:17 AM|LINK
could you list, please ,the controller action and the view ?
Maybe you did noy initialize model.name with something...
sskulkarni
Member
31 Points
74 Posts
Re: Getting value of Html.TextBoxFor(m => m.name)
Jul 22, 2010 09:50 AM|LINK
Hi ignatandrei
I have a controller named AccountsController in that i have action named public ActionResult ManageAccounts() and
[HttpPost]
Public ActionResult ManageAccounts(AccountsModel acc)
{ //Calling Fun from model
Return View();
}
In this Controller i get the value for Html.TextBoxFor(m=> m.name)
But what if i want this value on View (Accounts.aspx) also.
Actually i want to persist the value for this text box. I use this Text box for Filtering records of database. But when i click on Filter button i can access this value on Controller and i can get the filtered output also but the textbox becomes empty. I want to persist the Text box value after filtering records too.
Please Advice. Please Help
Thanks.
ignatandrei
All-Star
135142 Points
21676 Posts
Moderator
MVP
Re: Getting value of Html.TextBoxFor(m => m.name)
Jul 22, 2010 12:17 PM|LINK
replace
with
Return View(acc);
sskulkarni
Member
31 Points
74 Posts
Re: Getting value of Html.TextBoxFor(m => m.name)
Jul 22, 2010 01:11 PM|LINK
Hi ignatandrei
I tried replacing the View() with View(acc) but still i am unable to maintain Textbox Value.
How can we acees this value in View.
I tried doing it with javascript too.
Please suggest
ignatandrei
All-Star
135142 Points
21676 Posts
Moderator
MVP
Re: Getting value of Html.TextBoxFor(m => m.name)
Jul 22, 2010 03:36 PM|LINK
Between HttpGet and HttpPost this is automatically maintained . Please provide sample project for your ideas
bradwils
Contributor
5779 Points
691 Posts
Microsoft
Re: Getting value of Html.TextBoxFor(m => m.name)
Jul 22, 2010 10:33 PM|LINK
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Getting value of Html.TextBoxFor(m => m.name)
Jul 23, 2010 02:53 AM|LINK
Where is Accounts.aspx come into action?
Is you need to maintain value in different requests?
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
sskulkarni
Member
31 Points
74 Posts
Re: Getting value of Html.TextBoxFor(m => m.name)
Jul 23, 2010 11:32 AM|LINK
Hi All
I have tried setting the value of text box i.e Html.TextBoxFor(m=> m.name) in Controller too but it didnt work for me.
I have something like below.
public ActionResult Accounts(AccountsModel acc)
{
Models.AcccountsModel m = new AccountsModel();
m.name= acc.name;
return View("Accounts",m);
}
Please help and suggest.
How can i set again the Value for this TextBox . Is not their property like viewstate in Asp.Net MVC 2. so that i can persist the text box value.
Please Suggest.
Tracking
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Getting value of Html.TextBoxFor(m => m.name)
Jul 24, 2010 02:15 AM|LINK
I think this has been answered.
Since you are using a parameter which contains name. You don't neeed to do any thing else. TextBoxFor will be automatically bound to this value.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD