Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Controller is :--

[HttpPost]
public ActionResult Registration(StudentsModel mod,FormCollection frm)
{
StudentsModel model1 = new StudentsModel();
dbStudentsInfoEntities obj=new dbStudentsInfoEntities();
tbl_StudentRegistration tbl = new tbl_StudentRegistration();
string seach = Convert.ToString(frm["myHiddenText"]);
if (seach == "Save")
{
tbl.rollNumber = mod.RollNumber;
tbl.Name = mod.StudentsName;
tbl.City = mod.City;
tbl.Address = mod.Address;
obj.tbl_StudentRegistration.AddObject(tbl);
obj.SaveChanges();
var data = from n in obj.tbl_StudentRegistration
select n;
ViewBag.Collection = data;

}
else if (seach == "Search")
{

var rno=mod.RollNumber;
var data1 = from n in obj.tbl_StudentRegistration
where n.rollNumber==rno
select n;

foreach (var d in data1)
{
model1.RollNumber = d.rollNumber;
model1.StudentsName = d.Name;
model1.City = d.City;
model1.Address = d.Address;

}

}

return View("Registration", model1);
}
My model is :
C#
public class StudentsModel
    {
        public int RollNumber { get; set; }
        public string StudentsName { get; set; }
        public string City { get; set; }
        public string Address { get; set; }
}

My View is:-
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)


StudentsModel


@Html.LabelFor(a => a.RollNumber)


@Html.EditorFor(a => a.RollNumber,(@Model.RollNumber))
@Html.ValidationMessageFor(a => a.RollNumber)

<input type="submit" value="Search" id="Search"/>

@Html.LabelFor(a => a.StudentsName)


@Html.EditorFor(a => a.StudentsName, (@Model.StudentsName))
@Html.ValidationMessageFor(a => a.StudentsName)




@Html.LabelFor(a => a.City)


@Html.EditorFor(a => a.City,@Model.City)
@Html.ValidationMessageFor(a => a.City)



@Html.LabelFor(a => a.Address)


@Html.EditorFor(a => a.Address,@Model.Address)
@Html.ValidationMessageFor(a => a.Address)



<input type="submit" value="Save" id="SAVE" />




<input type="hidden" name="myHiddenText" id="myHiddenText" />


i want to display search model data on view in MVC3
Thanks for advance
Posted
Updated 18-Apr-14 20:56pm
v2
Comments
DotNet WeblineIndia 19-Apr-14 3:13am    
Model that you are passing to controller is a single record or multiple records? And if its a list, do you want to display that list on the view page? Can you please clarify your question
rahemani_1200 19-Apr-14 3:19am    
model have multiple record. and i want to display on each @Html.EditorFor according to its model property

you can do like this

C#
foreach (var item in Model.StudentList)
{

 @Html.EditorFor(model=> item.RollNumber)
 @Html.EditorFor(model=> item.StudentsName )
 @Html.EditorFor(model=> item.City )
 @Html.EditorFor(model=> item.Address )

}
 
Share this answer
 
v2
You have to make model strongly typed in order to get values from model.
e.g.
@model ApplicationName.models.StudentsModel
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900