I was wondering whether you guys could help me figure out what I'm missing that is making my AJAX request return my Content in a new window. I was trying to follow the post Using Ajax.BeginForm with ASP.NET MVC 3 Razor like a recipe book and apparently I'm missing something.
C:
[HttpPost]
public ActionResult AddOrganization ( string newOrgName )
{
PortalData PD = new PortalData();
if ((from thisorg in PD.orgs where thisorg.orgname == newOrgName select thisorg).Count() > 0)
{
return Content("Organization name '" + newOrgName + " 'already exists in database!", "text/html");
} // error if that organization exists
PD.orgs.InsertOnSubmit(new Organization { orgname = newOrgName });
try
{
PD.SubmitChanges();
} // try submitting to db
catch (Exception e)
{
return Content(e.Message, "text/html");
}
// if made it here, everything is good
return Content(newOrgName + " successfully added to database!", "text/html");
}
M:
</script>
<h3>Or Add New Organization</h3>
@using (Ajax.BeginForm("AddOrganization", "FileUpload", new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "new-org-output-msg" }))
{
<input type="text" name="newOrgName" />
<input type="submit" value="Add" />
}
<p><i id="new-org-output-msg"></i></p>
Submitting, say, "StackOverflow"
opens up a page with the source code nothing more than
Stack Overflow successfully added to database!
whereas my intention was my for that piece of text to be inside
<i id="new-org-output-msg"></i>