现在的位置: 首页 > 综合 > 正文

asp.net mvc 与jquery应用总结

2012年03月31日 ⁄ 综合 ⁄ 共 4396字 ⁄ 字号 评论关闭
程序员最喜欢的衬衫

1.DropDownList的Name和ViewData相同时SelectList 的selected 失效

1 SelectList ZDZListItem = new ListItem<HGZP.Model.Cjb_list_fxz>().GetListItem(ZDZList, "s_mch""s_mch",
2 orderInfo.CurrentZDZ);
3 
4 <% var aa = ((SelectList)ViewData["ZDZ111"]).SelectedValue.ToString();
5 if(!string.IsNullOrEmpty(aa)){ %>
6 <%:Html.DropDownListFor(OrderInfo => OrderInfo.ZDZ, ViewData["ZDZ111"as SelectList, new { id = "ddlZDZ"
  Style = "width:70px", @class = "focus", disabled = "true" })%><% }else{%>
7 <%:Html.DropDownListFor(OrderInfo => OrderInfo.ZDZ, ViewData["ZDZ111"as SelectList, new { id = "ddlZDZ"
  Style = "width:70px", @class = "focus" })%>
8 <%}%><%=Html.DropDownList("ddlSysid", (SelectList)ViewData["ZDZ111"])%>

2.使用jquery.form.js上传文件

服务器上传文件目录名称不能与controller名称相同,如果相同URL导航会出现错误

ajaxSubmit方法中dataType使用默认值不能用json

服务器端返回时要跳转到其他view

 

strJson = "{suc:1,msg:'保存成功!',orderId:'" + orderInfo.OrderId + "',orderDetailId:'" + orderInfo.OrderDetailId + @"',chargeId:'" + orderInfo.ChargeId + "',giftDetailId:'" + orderInfo.GiftDetailId + "',PaperBoxNum:'" + 
orderInfo.PaperBoxNum 
+ "',SubscibeNum:'" + orderInfo.SubscibeNum + "'}";

ViewData["strJson"= strJson;
return View("~/Areas/OrderInfoManage/Views/FileUploadSuccess.aspx", ViewData["strJson"]);

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%
String json 
= ViewData["strJson"].ToString();
Response.Write(json);
%>

 
如果附加其他属性(form以外的)可以如下处理

orderValue = JSON.stringify({
            orderId: $(
"#txtOrderId").val(),
            orderDetailId: $(
"#txtOrderDetailId").val(),
            paperBoxNumOld: $(
"#txtPaperBoxNumOld").val(),
            subscibeNumOld: $(
"#txtSubscibeNumOld").val(),
            chargeId: $(
"#txtChargeId").val(),
            giftDetailId: $(
"#txtGiftDetailId").val(),
            giftKCId: $(
"#txtGiftKCId").val(),
            paperName: $(
"#ddlNewsPaper option:selected").text(),
            giftName: $(
"#ddlGift option:selected").text(),
            isCheck: $(
"#txtIsCheck").val()
        });
        eval(
"orderValue = '" + JSON.stringify(JSON.parse(orderValue)) + "';");

$("#orderManageForm").ajaxSubmit({
                    url: 
"OrderManage/OrderAllAdd/",
                    
//contentType: "multipart/form-data",
                    
//dataType: 'json',
                    data: {
                        strJson: escape(orderValue)
                    },
                    
                    clearForm: 
false,
                    resetForm: 
false,
                    success: function (data) {
                        
try {
                            var json 
= eval("(" + data + ")");
                            alert(HTMLDeCode(json.msg));
                            
if (json.suc == 1) {
                                $(
"#txtOrderId").val(json.orderId);
                                $(
"#txtOrderDetailId").val(json.orderDetailId);
                                $(
"#txtChargeId").val(json.chargeId);
                                $(
"#txtGiftDetailId").val(json.giftDetailId);
                                $(
"#txtPaperBoxNumOld").val(json.PaperBoxNum);
                                $(
"#txtSubscibeNumOld").val(json.SubscibeNum);
                                orderValue 
= JSON.stringify({
                                    orderId: $(
"#txtOrderId").val(),
                                    isCheck: $(
"#txtIsCheck").val()
                                });
                                eval(
"orderValue = '" + JSON.stringify(JSON.parse(orderValue)) + "';");

                                jQuery("#orderGrid").jqGrid("setGridParam", {
                                    postData: { strJson: orderValue }
                                });
                                jQuery(
"#chargeGrid").jqGrid("setGridParam", {
                                    postData: { strJson: orderValue }
                                });
                                $(
"#orderGrid").trigger("reloadGrid");
                                $(
"#chargeGrid").trigger("reloadGrid");
                                saveFlag 
= "OrderUpdate";
                                $(
"#orderAllSaveBtn").attr("disabled""true")
                            }
                            $(
"#txtZDDate").focus().trigger("focusin");
                        } 
catch (e) {
                            alert(e);
                            
return;
                        }
JsonModel jsonObj 
= new JsonModel(System.Web.HttpUtility.UrlDecode(Request["strJson"]));

 

 

抱歉!评论已关闭.