Jinish Gandhi

Jinish Gandhi

  • NA
  • 83
  • 757

MVC4 Razor( How To get a specific value from database

Feb 29 2016 3:37 PM
i am using entity data model in mvc 4,i want specific value from dabase like as(select username from Emp where RollId="Textbox1.text")
but in mvc code
______________________________________________________________________ 
1.[view file code]-->GetResultView
@using(Html.BeginForm("GetResult","Login",FormMethod.Post))
{
<div>
@Html.TextBoxFor(Model=>Model.UserName)
</div>
<div>
@Html.DisplayFor(Model=>Model.RollId)
</div>
<div>
<input type="submit" value="GetResult" name="GetResult">
</div>
}
---------------------------------------------------------------------------------------------------------------------------- 
 2.[Controller]
public ActionResult GetResult()
{
return View();
}
[HttpPost]
public ActionResult GetResult(EmpInfo_Tbl ET)
{
using (db)
{
var v = db.EmpInfo_Tbl.Where(u => u.UserName.Equals(ET.UserName)).Select(u =>u.RollId).FirstOrDefault();
ViewBag.RollId = v.ToString();
}
return View(ET);
}
 ------------------------------------------------------------------------------------------------------------------------
 
 But in all thing i get value zero...but i didnt get excatly  values..so plz help me to find out..:)

Answers (3)