Click here to Skip to main content
15,028,402 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

--1)I have a upload button which is of submit type. The submit button posts the data in AjaxbeginForm in view.
And I have the below script reference(unobtrusive). If I comment the script reference then json method in controller gets the file. But the onsuccess(createJSTrees) method that is declared in View doesnot get fired.

--2)If I uncomment that script , controller method file is null. But the function() in view gets fired.

<pre lang="sql">public JsonResult GetStoreTillsDetailsByUpload(HttpPostedFileBase UploadedFile)


<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

@using (Ajax.BeginForm("GetStoreTillsDetailsByUpload", "QueryAnalyzer", new AjaxOptions { OnSuccess = "createJSTrees", OnFailure = "Error", HttpMethod = "Post" }, new { enctype = "multipart/form-data" }))

-------------onsuccess function in view-------------

function createJSTrees(js) {

            var testad = js;


                "json_data": {
                    "data": $.parseJSON(js)
                "plugins": ["checkbox", "themes", "json_data", "ui"]

---Json Method(controller method)-------------------------------------

<pre lang="xml">[HttpPost]
public JsonResult GetStoreTillsDetailsByUpload(HttpPostedFileBase UploadedFile)
    List&lt;Parent&gt; outputUploadStores = new List&lt;Parent&gt;();
    // SearchStoreTillsFinalViewModel finalStoreTillsList = new SearchStoreTillsFinalViewModel();
    outputUploadStores = UploadStoresTillsDetails(UploadedFile);// _autosearchstoretillsmapper.ExecuteMapperStoreTills(term,&quot;JsonStoreSearchResultStoreTills&quot;);
    JavaScriptSerializer se = new JavaScriptSerializer();
    var js = se.Serialize(outputUploadStores);
    return Json(js, JsonRequestBehavior.AllowGet);

    //Json(_nfrUsersMapper.GetUserRoles(id), JsonRequestBehavior.AllowGet);

--How to tackle this situation ? Kindly help me.
Updated 27-Mar-14 18:33pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900