Reputation: 171
In ASP .NET MVC 4 I'm trying to update a list on the page without performing an actual form submission and without a page refresh.
Upon button click, I'd like to call the list data in the method CheckPartNumber however the breakpoint is never hit. No errors are thrown. I can hit a debugger; in the JavaScript but no errors are found.
<script type="text/javascript">
function getParts(searchString) {
debugger;
$.ajax({
url: '@Url.Action("CheckPartNumber", "PartController")',
type: 'GET',
dataType: 'json',
// we set cache: false because GET requests are often cached by browsers
// IE is particularly aggressive in that respect
cache: false,
data: { searchString: searchString },
success: function (part) {
$('#PartNumber').val(part.PartNumber);
//$('#LastName').val(person.LastName);
}
});
}
</script>
<div class="editor-field">
<input type="text" id="part" />
<input type="button" value="Search" onclick="getParts('test')" />
</div>
public class PartController : Controller
{
private InventurWebEntities db = new InventurWebEntities();
[HttpGet]
public ActionResult CheckPartNumber(string searchString)
{
var parts = db.Parts.Take(10);
return Json(parts, JsonRequestBehavior.AllowGet);
}
}
Upvotes: 2
Views: 623
Reputation: 119076
You are constructing the wrong URL. When using Url.Action
you need to drop the Controller
suffix. So this:
@Url.Action("CheckPartNumber", "PartController")
Becomes this:
@Url.Action("CheckPartNumber", "Part")
Upvotes: 3