不显眼的脚本标记不起作用

不显眼的脚本标记不起作用

本文介绍了使用AjaxBeginForm上传文件,不显眼的脚本标记不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

--scenario

--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)
{</pre>





----查看-----------------------------------



< 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函数在视图中-------------





----View-----------------------------------

<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) {
            debugger;
            alert('hi');

            var testad = js;

            alert(testad.Message);
            alert(testad["Message"]);

            $("#divsearchResult").jstree({
                "json_data": {
                    "data": $.parseJSON(js)
                },
                "plugins": ["checkbox", "themes", "json_data", "ui"]
            });
        }





--- Json方法(控制器方法)------------- ------------------------





---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);
}</pre>










--How to tackle this situation ? Kindly help me.

推荐答案






--- Json方法(控制器方法)------------- ------------------------





---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);
}</pre>










--How to tackle this situation ? Kindly help me.


这篇关于使用AjaxBeginForm上传文件,不显眼的脚本标记不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 09:42