Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to search Team by Team name provided.

View:
@Html.ActionLink("Create New", "Create")

@using (Html.BeginForm()){

@Html.EditorFor(model => model.TeamName)
@Html.ValidationMessageFor(model => model.TeamName)


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

Controller:
[HttpPost]
public ActionResult TeamSearch(Team Name)
{
string name = Name.ToString();
Team result = (from c in context.Teams
where c.TeamName ==name
select c).FirstOrDefault();


return View(result);

}

But It shows null on name when I convert Name.Tostring(). Hence result also get NULL .

Can you please tell me where is the problem??
Posted

I guess, that should be like...
C#
Team.TeamName.ToString();
 
Share this answer
 
v2
Comments
rayhan12345 12-Jul-14 2:35am    
Here, you can see that Name is an object of type Team.
public ActionResult TeamSearch(Team Name)
and here Name shows the string passed from the view, but When I convert it to string it doesn't show nothing.
Modified Code for controller:

public ActionResult TeamSearch(Team Name)
{
string name = Name.TeamName;

Team result = (from c in context.Teams
where c.TeamName ==name
select c).FirstOrDefault();


return View(result);

}
 
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