I'm trying my hand and Asp.net MVC 4 and having an issue with an Ajax form returning a whole new page instead of just updating a div.
Here's the razor html code:
<div class="All">
<div class="Search">
@using (Ajax.BeginForm( new AjaxOptions { UpdateTargetId = "CurrentSku" } ))
{
@Html.Label("Enter Sku:")
@Html.TextBox("textBox1")
<input type="submit" value="Find" />
}
</div>
<div id="CurrentSku">
<span>No Sku selected.</span>
</div>
and here's the controller:
public ActionResult Index()
{
// Pay no attention to this, just a place holder
return View( db.xInventoryExt.Take(1) );
}
[HttpPost]
public ActionResult Index(string textBox1)
{
if (db.xInventoryExt.Count(a => a.InvtID == textBox1) < 1)
{
return Content("Sku not found.", "text/html");
}
var ret = db.xInventoryExt.First(b => b.InvtID == textBox1);
return Content(ret.ToString(), "text/html");
}
I was reading that this sometimes happens when not including MicrosoftAjax.debug.js but I can't find a copy of that file anywhere.