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