作重視項目時,前臺代碼中藝員編號須要通過後臺傳值到另外一個頁面,未料當編號中有中文時,傳到後臺就已是亂碼了,經搜索,發現一個解決辦法是用js對中文encode後再在後臺用Server.UrlDecode()解密:ide
前臺:this
- <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:spa
- 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);
- }
後臺:code
- 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);
- }