I am trying to store a value from a textbox using tempdata; (just like a session). I then need to pass that variable to a controller later on. My code is below:
First Name begins with: TempData("GetName") = @Html.TextBox;
Error Message: Cannot convert method group 'TextBox' to non-delegate type 'object'. Did you intend to invoke the method?
TempData is a session variable. you should set in the controller. @Html.TextBox is a method that return a string snippet of html. it requires parameter that you failed to provide. that is the error.
the ...TempData("GetName") in the sample code, is just a string literal, that will display in the browser as:
syed.sami
Member
112 Points
98 Posts
tempdata
Nov 17, 2011 02:38 PM|LINK
I am trying to store a value from a textbox using tempdata; (just like a session). I then need to pass that variable to a controller later on. My code is below:
First Name begins with: TempData("GetName") = @Html.TextBox;raduenuca
All-Star
24675 Points
4250 Posts
Re: tempdata
Nov 17, 2011 02:43 PM|LINK
I'm sorry but you had a wrong start with MVC. Have a round of tutorials from here:
http://www.asp.net/mvc/
Radu Enuca | Blog
bruce (sqlwo...
All-Star
36656 Points
5438 Posts
Re: tempdata
Nov 17, 2011 02:48 PM|LINK
???. your code makes no sense.
TempData is a session variable. you should set in the controller. @Html.TextBox is a method that return a string snippet of html. it requires parameter that you failed to provide. that is the error.
the ...TempData("GetName") in the sample code, is just a string literal, that will display in the browser as:
First Name begins with: TempData("GetName") =
syed.sami
Member
112 Points
98 Posts
Re: tempdata
Nov 17, 2011 02:50 PM|LINK
Radu,
Can you reply with the correct syntax please. i have read the MVC articles but not getting it right.
Gaspard
Contributor
2066 Points
416 Posts
Re: tempdata
Nov 17, 2011 02:53 PM|LINK
There is a tutorial at this web page for ViewBag, ViewData and TempData
http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications
Regards
raduenuca
All-Star
24675 Points
4250 Posts
Re: tempdata
Nov 17, 2011 02:54 PM|LINK
There is no syntnax to reply with....you need to go over some tutorials. In short
Radu Enuca | Blog
syed.sami
Member
112 Points
98 Posts
Re: tempdata
Nov 17, 2011 03:10 PM|LINK
Please see the codes below. Now please tell me what I am doing wrong?
Code for controller:
Controller: public ViewResult SearchUser() { return View(); } [HttpPost] public ViewResult SearchUser(GetName) { GetName = GetName(); TempData["GetName"] = GetName; }@{ ViewBag.Title = "Create"; } <h2> Searching a User (Step 1 of 3) :</h2> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <table> First Name begins with: TempData("GetName") = @Html.TextBoxFor<>; </table> <p> <b><input type="submit" value="Submit" /> </b> </p> </fieldset> }raduenuca
All-Star
24675 Points
4250 Posts
Re: tempdata
Nov 17, 2011 03:12 PM|LINK
replace this
First Name begins with: TempData("GetName") = @Html.TextBoxFor<>;
with
First Name begins with: @Html.TextBox("GetName")
and what is this supposed to do?
GetName = GetName(); //overrides the GetName
TempData["GetName"] = GetName;
you will need to return a view from here also
Radu Enuca | Blog
syed.sami
Member
112 Points
98 Posts
Re: tempdata
Nov 17, 2011 04:00 PM|LINK
Here is the controler code:
public ActionResult Search() { return View(); } [HttpPost] public ViewResult SearchUser("GetName") { @ViewBag = "You are tried to search for" & GetName return View(); }ignatandrei
All-Star
134527 Points
21579 Posts
Moderator
MVP
Re: tempdata
Nov 17, 2011 04:01 PM|LINK
This would not even compile( C#,VB.NET mix and bad parameter) . Please copy code from your action .