ajax form issue for partial view on module

Topics: General, Writing modules
Mar 17, 2012 at 5:10 PM
Edited Mar 17, 2012 at 5:19 PM

Hello everyone,

Anybody have an experience in ajax form submitting on partial view?

I tried to use it on my orchard project.

But I got a javascript runtime error when I try to submit: "sys is not defined".

- controller

 

public ActionResult List()
{
    ...
    return View("List", model);
}

 

 

[HttpPost]
public PartialViewResult UpdateCollection(CollectionViewModel model)
{
    ...
    return PartialView("_Collections", model);
}

 

- viewer

List.cshtml

 

....
@using (Html.BeginForm("UpdateAll", "Admin", ......))
{
    ...
}

@using (Script.Foot())
{
    <script type="text/javascript">
        function beginCollecting(args){
            $('#editor_container').html('<img src="......../loading.gif"');
        }
        function failureCollecting(){
            ....
        }
        function successCollecting(){
            ....
        }
    </script>
}

<section id="collection_sec">
@{Html.RenderPartial("_Collections", Model.collections);}
</section>

_Collections.cshtml

 

...
@{
    Script.Require("jQuery").AtHead();
    Script.Require("jquery_unobtrusive_ajax").AtHead();
}

@using(Ajax.BeginForm("UpdateCollection", "Admin", null, new AjaxOptions { InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace, UpdateTargetId = "collection_sec", OnBegin = "beginCollecting", OnSuccess = "successCollecting", OnFailure="failureCollecting", null}))
{
    @Html.DropDownListFor(x=>x.CollectionIndex, Model.CollectionDic)
    ...
    <button type="submit">
        @T("Update")
   </button>
}

 

 

When I try to click the dropdownlist and When I try to submit on collection partial view section, the javascript runtime error is occurred.

So I think the problem is on the Ajax.InsertionMode.Replace option or jquery-conflecting.

But I don't know how can I fix it.

Anyone to help me?

Thanks

Coordinator
Mar 17, 2012 at 9:09 PM

Do NOT use the old Ajax stuff with Orchard. It's using a long-deprecated framework. Just use jQuery.

Mar 18, 2012 at 2:10 AM

I decided to use jquery directly.

Thanks bertrandleroy!