I want search record from the sql server data base but i can't search the record my index form code is as follows:
<%using (Html.BeginForm("Submit","Candidates",FormMethod.Post)){ %>
Enter keyword to search
<div id="searchBox">
<input type= "text" name="FirstName"
id="FirstName" maxlength="70" onfocus="this.value=''" value=""/><br />
<input id="search" type="submit" value="Search" />
</div>
<% } %>
mysql Repository code
public class SqlCandidatesRepository:ICandidatesRepository
{
private Table<Candidate> candidatesTable;
public SqlCandidatesRepository(string connectionString)
{
candidatesTable = (new DataContext(connectionString)).GetTable<Candidate>();
}
public IQueryable<Candidate> SearchCandidate(string key)
{
var candidate = (from p in
candidatesTable
where p.FirstName == key
开发者_如何学JAVA select p);
return candidate;
}
}
Controller code
public class CandidatesController : Controller
{
//
// GET: /Products/
private ICandidatesRepository candidatesRepository;
public CandidatesController(ICandidatesRepository candidatesRepository)
{
this.candidatesRepository = candidatesRepository;
}
public ActionResult CandidateSearch(string name)
{
var candidate = candidatesRepository.SearchCandidate(name);
return View(candidate.ToList());
}
}
Exception trace :
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /Home/Submit**
Please help and give me sample code thanks.
Your markup is creating a form which will post to the action "Submit" on the "Candidates" controller.
I don't know what your controller is called but your action is called "CandidateSearch".
Change your markup to: (assuming that your page was rendered by the same controller that it is posting back to).
<% using (Html.BeginForm("CandidateSearch")){ %>
OR
<% using (Html.BeginForm("CandidateSearch","TheControllerName")){ %>
精彩评论