Stored procedure,Parameter,bind Dropdownlist

Posted by Raja_89 under ASP.NET MVC on 11/3/2016 | Points: 10 | Views : 2722 | Status : [Member] | Replies : 1
Hai
I am a task to take the input from textbox and pass it to as parameter for retrieving the data from sql database in MVC

Controller code
[HttpPost ]
[ValidateAntiForgeryToken]
public ActionResult Index(AppUser objAppusr)
{
if (ModelState.IsValid )
{

using (AppDbsLoginModel dbAppsdbsloginent= new AppDbsLoginModel () )

{
//var objseldetails= dbAppsdbsloginent.AppUsers.Where(a => a.UserId.Equals(objAppusr.UserId) && objAppusr.ProductId.Equals(objAppusr.ProductId)).FirstOrDefault();
var objseldetails = dbAppsdbsloginent.AppUsers.Where(a => a.UserId.Equals(objAppusr.UserId));
if (objseldetails !=null )
{
// Session["Prdid"] = Convert.ToString(objseldetails.ProductId);
Session["Userid"] = Convert.ToString(objAppusr.UserId );
using (var objsqlcon = new SqlConnection(Convert.ToString(ConfigurationManager.ConnectionStrings["AppDbsCon"])))
{
var cmd = new SqlCommand("Get_UsersInfo", objsqlcon);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserId", Session["Userid"]);
objsqlcon.Open();
cmd.ExecuteNonQuery();
objsqlcon.Close();

}
//return RedirectToAction("UserDashBoard");

}
}
}
return View(objAppusr);
}


View
@using (Html.BeginForm("Index", "AppLogin", FormMethod.Post))//LoginHome
{
<fieldset>
<legend>Mvc Simple Login Application Demo</legend>

@Html.AntiForgeryToken()
@Html.ValidationSummary(true)

@if (@ViewBag.Message != null)
{<div style="border: 1px solid red">
@ViewBag.Message
</div>
}
<table>
<tr>
<td>@Html.LabelFor(a => a.UserId )</td>
<td>@Html.TextBoxFor(a => a.UserId )</td>
<td>@Html.ValidationMessageFor(a => a.UserId )</td>
</tr>
<tr>
<td>
@Html.LabelFor(a => a.ProductId )
</td>
<td>
@* @Html.DropDownList ("Drpdownlist",ViewBag. )*@
</td>


Query Output:

A
B
C
D

How can i proceed




Responses

Posted by: Manicse on: 11/23/2016 [Member] Bronze | Points: 25

Up
0
Down
Hi,

What is your actual doubt?
Can you explain us what output you are expecting from your code?

Mani.R

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response