做重视项目时,前台代码中艺员编号需要经过后台传值到另一个页面,未料当编号中有中文时,传到后台就已经是乱码了,经搜索,发现一个解决办法是用js对中文encode后再在后台用Server.UrlDecode()解密:
前台:
- <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">
- <span>修改经历</span></a>
js:
- function encodeCh(){
- var href = $("#btnAddExperience").attr("href");
- var front = href.substr(0,href.indexOf("code")+5);
- var code = href.substr(href.indexOf("code")+5);
- var encodedCode = escape(code);
- var newHref = front + encodedCode;
- $("#btnAddExperience").attr("href",newHref);
- }
后台:
- public ActionResult ExperienceEdit(int experienceId, int artisteId)
- {
- string code = Request.QueryString["code"]; // Request.QueryString接收get传值
- ViewData["ArtisteId"] = artisteId;
- ViewData["code"] = Server.UrlDecode(code);
- PerformanceExperienceData model = new PerformanceExperienceData();
- if (experienceId != 0)
- {
- ArtisteService ass = new ArtisteService();
- model = ass.GetExperienceById(experienceId);
- }
- return View(this.ViewPath("ExperienceEdit"), model);
- }