将JsonResult对象从视图中的javascript函数传递给控制器
pass JsonResult object from javascript function in View to Controller
如何将JsonResult对象从视图中的javascript函数传递到控制器动作而没有Ajax调用-只是javascript - window.location.href = url?
我得到JsonResult对象从控制器动作到javascript函数通过Ajax调用。然后我想把这个对象传递给其他控制器动作,但我得到的对象引用属性为空。
View中的javascript函数:
function order(model) {
$('#details-container').html("<h2>Loading Complete Frame Module. Please wait...</h2>");
$.p({
url: '@Url.Action("CompleteFrameBrandDetails", "PacCompleteFrame")',
data: { item: model },
success: function (xml) {
if (xml.Success) {
$.p({
url: '@Url.Action("GlassCompleteFrame", "PacModule")',
data: JSON.stringify({ b2bXml: xml.Data }),
success: function (model) {
var pacModuleModel = {
Mode: model.Data.Mode,
IframeUrl: model.Data.IframeUrl.toString(),
CustomerNumber: model.Data.CustomerNumber.toString(),
ReadOnly: model.Data.ReadOnly,
GlassXml: model.Data.GlassXml.toString(),
Price: parseFloat(model.Data.Price),
Comission: model.Data.Comission.toString(),
Permissions: null,
Language: model.Data.Language.toString()
};
// here are all values in model.Data correct
// but then I can't figure out how to pass it to Controller Action without Ajax call - just with javascript command
var url = '@Url.Action("GlassCompleteFrameView", "PacModule", "__view__")';
window.location.href = url.replace("__view__", model.Data); //pacModuleModel
}
});
} else {
$.alert({
message: 'error while trying to load xml details'
});
}
}
});
}
My Controller Action:
public ActionResult GlassCompleteFrameView(PacModuleModel model)
{
// here I get object module but
// model.CustomerNumber = null
// model.GlasXml = null
// model.Price = null
// ...
return View("Glass", model);
}
我也有这样的模型自动Json绑定,但不工作:
public enum ModuleMode
{
ByProduct,
ByRecipe
}
public partial class PacModuleModel
{
private PacPermissionModel permissionModel;
public ModuleMode Mode { get; set; }
public string IframeUrl { get; set; }
public string CustomerNumber { get; set; }
public bool ReadOnly { get; set; }
public string GlassXml { get; set; }
public double? Price { get; set; }
public string Comission { get; set; }
public PacPermissionModel Permissions
{
get
{
if (permissionModel == null)
{
permissionModel = new PacPermissionModel();
}
return permissionModel;
}
}
public string Language { get; set; }
}
在控制器
public JsonResult GlassCompleteFrameView(PacModuleModel model)
{
// here I get object module but
// model.CustomerNumber = null
// model.GlasXml = null
// model.Price = null
// ...
return Json(model, JsonRequestBehavior.AllowGet);
}
问题出在模型上。它超过45000字符长。现在我使用会话变量在GlassCompleteFrameView(PacModuleModel模型)中获得模型,并且工作完美。
public ActionResult GlassCompleteFrameView(PacModuleModel model)
{
model = Session["xml"] as PacModuleModel;
return View("Glass", model);
}
相关文章:
- AngularJS,angular.element($0).scope()揭示了每个控制器的函数
- 为什么我的控制器没有启动函数.js脚本
- 从全局函数调用Ember控制器上的方法
- AngularJS:控制器中的函数被模板多次调用
- 在Angular中呈现DOM对象时,如何调用控制器中指定的函数
- Angular,从指令控制器中的控制器触发函数
- 如何在指令链接函数中使用从控制器传递的筛选器
- 从控制器Angularjs调用链接函数
- 角度指令控制器:参数不是函数,未定义
- 如何从页面中的jquery调用angular js函数控制器
- angularjs调用事件中控制器的一个函数
- 通过指令在控制器中执行javascript函数
- AngularJS执行指令模板中的控制器函数
- 从指令链接函数监视控制器作用域
- AngularJS:如何与其他控制器共享作用域函数和变量
- 如何在angular ui模态控制器中定义函数
- 当指令中已经给定作用域时,如何访问控制器中声明的函数
- AngularJS:如何调用指令中定义的函数'控制器的作用域
- 我是否需要将工厂调用放在控制器的函数中
- 如何在角函数控制器中传递绑定值