This is my View.cshtml
<h3>Search One Drive</h3>
<script src="~/Scripts/jquery-2.1.0.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
@using (Ajax.BeginForm("test", "Home", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "result" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Search</legend>
<div id="result"></div>
<div class="editor-label">
@Html.LabelFor(model => model.queryTerm)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.queryTerm)
@Html.ValidationMessageFor(model => model.queryTerm)
</div>
</fieldset>
<p>
<input type="submit" value="Submit" />
</p>
}
I have a corresponding ActionResult in my Home Controller:
[HttpPost]
public ActionResult test(Model testModel)
{
string query = testModel.queryTerm;
return Content("hi " + query);
}
It is a MVCV4 web app with razor. So, when I get to the view page and enter a query and hover over "Submit", I see Home/test method get display (upon hover). But when I click on Submit, the control is not passed on the ActionResult test() in the HomeController.
Am I missing something?
Thanks!
Ok, this was the fix:
I did not have a parameterless constructor in my Model Class. So, when this call was being made, it was unable to create an instance. Once, I added the default constructor, it started functioning well.
Fixed this with the help of Fiddler.