Hi, I'm currently trying to get a form for publishing a controller using AJAX, but I haven’t gotten lucky yet, I tried to get a form for sending values in the form to the controller on the submit form, but this will not work, does anyone know why ?:
CSHTML:
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Abintegro Search Prototype</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script> $("#submitsearch").click(function (e) { e.preventDefault(); var form = $("#searchform"); $.ajax({ url: "Search/GetSearchDetails", data: form.serialize(), type: 'POST', success: function (data) { </script> <script> $(function () { var searchPhrases = [ "Zep Solutions", "Wetherby Consultants Ltd", "Webmploy", "WATS Recruitment Ltd", "Vital Resources", "VG Charles and Co", "Veredus UK", "Venn Group", "VanDuo Consulting" ]; $("#phrases").autocomplete({ source: searchPhrases }); }); </script> </head> <body> <form id="searchform" name="searchform"> <div class="company-textbox"> <label for="companyname">Company Name</label> <input id="phrases" name="companyname"> </div> <br /> <div class="specialities"> <label for="specialities-dropdown">Specialities:</label> <select name="specialities-dropdown"> <option value="Consumer Products & Services">Consumer Product & Services</option> <option value="Support Services">Support Services</option> <option value="Communication & Entertainment">Communication & Entertainment</option> <option value="Business & Professional Services">Business & Professional Services</option> <option value="Public Sector">Public Sector</option> <option value="Not for profit">Not for profit</option> <option value="Sports Information">Sports Information</option> </select> </div> <br /> <div class="category"> <label for="category-dropdown">Category:</label> <select name="category-dropdown"> <option value="Generalist">Generalist</option> <option value="Specialist">Specialist</option> <option value="Exec Search">Exec Search</option> <option value="Interim Management">Interim Management</option> </select> </div> <br /> <div class="location-dropdown"> <label for="location-dropdown">Location:</label> <select name="Location"> <option value="London">London</option> <option value="Bristol">Bristol</option> <option value="Manchester">Manchester</option> <option value="Birmingham">Birmingham</option> </select> </div> <input type="submit" value="Submit" name="submitsearch" id="submitsearch"> </form> </body> </html>
Controller:
[HttpPost] public string GetSearchDetails(string companyName, string specialities, string category, string location) { return liveSearchRepository.GetUserInputResults(companyName,specialities,category,location); }
source share