ajax调用mvc action使用实体参数

 
  HTML端js代码  
  var url='CAR/GetCAR' 	 
  var JSONStr = String.format('{"BU":"{0}","CARType":"{1}"}', BU, CarType);

    htmlobj = $.ajax({
        url: url,
        type: "POST",
        async: false,
        contentType: "application/json",
        data: JSONStr, 
    });
    
    $("#divBody").html(htmlobj.responseText);  


 
    Control 层中Action 
   [HttpPost]          
   public ActionResult CAROverallTrackingProjectStep(CARModel cm)          
   {                 
     ViewBag.param =  JsonConvert.SerializeObject(cm);    
     return View();           
   }           
   [HttpPost]       
    public ActionResult CAROverallTrackingProjectStep_(CARModel cm)     
    {                     
      ViewBag.param = JsonConvert.SerializeObject(cm);        
      return PartialView("CAROverallTrackingProjectStep");       
    }

CARModel实体类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CAR.Models{ 
   public class CARModel    {  
      private string bu;      
      public string BU        
      {          
       set          
         {            
           bu = value;      
         }           
       get          
         {                
            return bu != null ? bu : "";          
         }       
      }       

 private string cartype;        
 public string CARType        
 {            
   set          
    {              
     cartype = value;          
    }           
   get         
   {             
     return cartype != null ? cartype : "";          
   }       
  }  
 }
}

HTML网页得到参数方法
<input type="text" id="txtParam" value="@ViewBag.Param" style="width:200px" >






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值