asp.net mvc 与jquery应用总结

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"]));

 

 

posted on 2011-05-20 16:33  J-Pei  阅读(550)  评论(0编辑  收藏  举报

导航