做重视项目时,前台代码中艺员编号需要经过后台传值到另一个页面,未料当编号中有中文时,传到后台就已经是乱码了,经搜索,发现一个解决办法是用js对中文encode后再在后台用Server.UrlDecode()解密:

前台:

  1. <a class="edit" id="btnEditExperience" href="@Url.Action("ExperienceEdit")?experienceId={experience_obj}&artisteId=@Model.Id&code=@Model.Code" onclick="correctHref(this,'Artiste_Experience_Table');" rel="ExperienceEdit_Dialog" target="dialog"  mask="true" height="300" width="500"  closeBackground="false" submitBtn="dialogFormSubmit" isAttachShadow = "true"> 
  2.                 <span>修改经历</span></a> 

js:

  1. function encodeCh(){ 
  2.         var href = $("#btnAddExperience").attr("href"); 
  3.         var front = href.substr(0,href.indexOf("code")+5); 
  4.         var code = href.substr(href.indexOf("code")+5);  
  5.         var encodedCode = escape(code); 
  6.         var newHref = front + encodedCode; 
  7.         $("#btnAddExperience").attr("href",newHref);  
  8.     } 

后台:

  1. public ActionResult ExperienceEdit(int experienceId, int artisteId) 
  2.         { 
  3.             string code = Request.QueryString["code"]; // Request.QueryString接收get传值
  4.             ViewData["ArtisteId"] = artisteId; 
  5.             ViewData["code"] = Server.UrlDecode(code); 
  6.  
  7.             PerformanceExperienceData model = new PerformanceExperienceData(); 
  8.             if (experienceId != 0) 
  9.             { 
  10.                 ArtisteService ass = new ArtisteService(); 
  11.                 model = ass.GetExperienceById(experienceId); 
  12.             } 
  13.             return View(this.ViewPath("ExperienceEdit"), model); 
  14.         }