So I am trying to show some text that i retrieved from the database and wanted to show them as a label or just show up on a page. I am having trouble displaying this text and here is what i have:
controller:
public ActionResult _StudentName(int id)
{
id = 12;
var model = new StudentNameModel();
using (var db = new School())
{
var result = from s in db.Students
where s.ID == id
select s.StudentName;
model.StudentName = result.ToString();
}
return View(model);
}
My Model:
public class StudentNameModel
{
[Display(Name = "Student Name")]
public string StudentName { get; set; }
}
My view:
@model Adams.Models.StudentNameModel
<fieldset>
@Html.LabelFor(m => m.StudentName)
@Html.TextBoxFor(m => m.StudentName)
</fieldset>
_StudentNameand try debugging and check whether result has any value or not[HttpPost]on your controllers action, please check ? Also your ControllerAction is prepended with_. Is your view name is_StudentName.cshtml? If not please your controllers action toStudentNamein your controllers action to get it hit