Atbenning
asked on
ASP.Net MVC Ajax not writing correctly
I have a page using an ajax form with ajax.beginform, only instead of updating the target div on submit, it renders a new page. The ajax script references are in the site.master file. Code below.
//on the view page
<% using (Ajax.BeginForm("AddSurveysAJAX",
new AjaxOptions { UpdateTargetId = "Test", InsertionMode = InsertionMode.Replace }))
{ %>
<%= Html.Hidden("itemID", Model == null ? ViewData["itemID"] : Model.ItemID) %>
<%= Html.ListBox("SurveysLst", ViewData["Surveys"] as MultiSelectList)%>
<input type="submit" value=">>>" />
<%= Html.ListBox("SelSurveysLst", ViewData["ItemSurveys"] as MultiSelectList)%>
<div id="Test"></div>
<% } %>
//in the controller
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddSurveysAJAX(FormCollection formValues)
{
return Content("Testing 123");
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the reminder to check firebug, showed that the path was off
One suggestion that I'd make for your script URLs is to use a helper method
I create a helper method
public static string JQuery(this UrlHelper helper, string fileName)
{
return helper.Content(String.Form at("~/asse ts/script/ jquery/{0} ", fileName));
}
public static string MicrosoftAjax(this UrlHelper helper, string fileName)
{
return helper.Content(String.Form at("~/asse ts/script/ microsofta jax/{0}", fileName));
}
and then use it
<script language="javascript" src="<%= Url.JQuery("jquery-1.3.2.m in.js") %>" type="text/javascript"></s cript>
<script language="javascript" src="<%= Url.JQuery("jquery.form.js ") %>" type="text/javascript"></s cript>
I create a helper method
public static string JQuery(this UrlHelper helper, string fileName)
{
return helper.Content(String.Form
}
public static string MicrosoftAjax(this UrlHelper helper, string fileName)
{
return helper.Content(String.Form
}
and then use it
<script language="javascript" src="<%= Url.JQuery("jquery-1.3.2.m
<script language="javascript" src="<%= Url.JQuery("jquery.form.js
ASKER
It worked fine after I made the changes below. I don't know why the path wasn't reading right, because I had the jquery library referenced the exact same way and it was working fine.
Open in new window