Hi Everyone! I'm completely new to ASP.NET and have only spent maybe 15 hrs learning it. I need some help! I'm trying to create a simple web page and I was following the Movies tutorial and modifying the code as needed on my end for the web application I
am attempting to build. I have a couple administration pages working for me: Codes and Types but have hit a wall.
Scenario: I have modified the Create.cshtml to have the following: (this has a label and allows me to input a quantity value needed)
<div class="editor-label">
@Html.Label("txtQty", "Please enter the quantity of labels you would like to print: ")
@Html.TextBox("qty")
</div>
On the Create view I have a text box that when I input a specified number a stored procedure needs to take that value and pass as the variable. The stored procedure is usp_codecreation needing @Qty value which this value should be passed from the @Html.Textbox("qty"). This is where I am at a loss and completely confused.
On the CodeController.cs I have modified the [HttpPost] so many times that this is now what I have:
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(int txtQty)
{
string connect = System.Configuration.ConfigurationManager.AppSettings["DB"];
SqlConnection scn = new SqlConnection(connect);
string sp = "usp_CodeCreation";
SqlCommand usp_CodeCreation = new SqlCommand(sp, scn);
SqlParameter pm = new SqlParameter(Request["txtQty"], SqlDbType.Int);
usp_CodeCreation.Parameters.Add(pm);
return RedirectToAction("Index");
}
I know the above is all over the place and I'm not referencing things correctly! :-| I have run SQL traces to see if the stored procedure is being accessed and it does not seem to be at all. I know this is lack of knowledge on my end. Can someone assist
me in getting this corrected? If I am leaving out necessary information please let me know and I will add to the post.
Noonies
Member
2 Points
2 Posts
Passing a value from a View to a Controller using ASP.NET MVC3 C#
Mar 01, 2012 08:13 PM|LINK
Hi Everyone! I'm completely new to ASP.NET and have only spent maybe 15 hrs learning it. I need some help! I'm trying to create a simple web page and I was following the Movies tutorial and modifying the code as needed on my end for the web application I am attempting to build. I have a couple administration pages working for me: Codes and Types but have hit a wall.
Scenario: I have modified the Create.cshtml to have the following: (this has a label and allows me to input a quantity value needed)
<div class="editor-label"> @Html.Label("txtQty", "Please enter the quantity of labels you would like to print: ") @Html.TextBox("qty") </div>On the Create view I have a text box that when I input a specified number a stored procedure needs to take that value and pass as the variable. The stored procedure is usp_codecreation needing @Qty value which this value should be passed from the @Html.Textbox("qty"). This is where I am at a loss and completely confused.
On the CodeController.cs I have modified the [HttpPost] so many times that this is now what I have:
public ActionResult Create() { return View(); } [HttpPost] public ActionResult Create(int txtQty) { string connect = System.Configuration.ConfigurationManager.AppSettings["DB"]; SqlConnection scn = new SqlConnection(connect); string sp = "usp_CodeCreation"; SqlCommand usp_CodeCreation = new SqlCommand(sp, scn); SqlParameter pm = new SqlParameter(Request["txtQty"], SqlDbType.Int); usp_CodeCreation.Parameters.Add(pm); return RedirectToAction("Index"); }I know the above is all over the place and I'm not referencing things correctly! :-| I have run SQL traces to see if the stored procedure is being accessed and it does not seem to be at all. I know this is lack of knowledge on my end. Can someone assist me in getting this corrected? If I am leaving out necessary information please let me know and I will add to the post.
variables
ignatandrei
All-Star
134873 Points
21619 Posts
Moderator
MVP
Re: Passing a value from a View to a Controller using ASP.NET MVC3 C#
Mar 01, 2012 08:25 PM|LINK
must be
variables
Noonies
Member
2 Points
2 Posts
Re: Passing a value from a View to a Controller using ASP.NET MVC3 C#
Mar 01, 2012 08:52 PM|LINK
Thank you for the link! I will read up on that site. And yes I do know I need to spend more time learning. Thanks again!
variables