问题描述
--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<Parent> outputUploadStores = new List<Parent>();
// SearchStoreTillsFinalViewModel finalStoreTillsList = new SearchStoreTillsFinalViewModel();
outputUploadStores = UploadStoresTillsDetails(UploadedFile);// _autosearchstoretillsmapper.ExecuteMapperStoreTills(term,"JsonStoreSearchResultStoreTills");
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<Parent> outputUploadStores = new List<Parent>();
// SearchStoreTillsFinalViewModel finalStoreTillsList = new SearchStoreTillsFinalViewModel();
outputUploadStores = UploadStoresTillsDetails(UploadedFile);// _autosearchstoretillsmapper.ExecuteMapperStoreTills(term,"JsonStoreSearchResultStoreTills");
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上传文件,不显眼的脚本标记不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!