ajax调用mvc action使用实体参数

前端之家收集整理的这篇文章主要介绍了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" >
原文链接:https://www.f2er.com/ajax/160658.html

猜你在找的Ajax相关文章