跳到主要內容

發表文章

目前顯示的是有「MVC」標籤的文章

[ASP.NET] 上傳圖片加浮水印

Model [.CS]         [HttpPost]         public int WebUplaodFile()         {             var upfile = Request.Files["myFile"]; ;             if (upfile != null)             {                 new ImgService().ImgMarkImg(Server.MapPath("~/Image"), upfile);             }                       return 1;         } Service [.CS]         public void ImgMarkImg(string spath, HttpPostedFileBase myfile)         {             //浮水印檔案路徑             string MarkImgPath = spath + "/imgmark.png";             //暫存檔路徑           ...

[ASP.NET] MVC Get Model Error Message

*Controller [.cs]  public void Edit(EditModel data) {             if (ModelState.IsValid)             {                 //is valid data             }             else             {                 //get error message                 var errors = ModelState.Select(x => x.Value.Errors)                          .Where(y => y.Count > 0)                          .ToList();                           } }

[HTML/MVC] 連動 Dropdownlist 後端->View

[.CS]             var result = new SelectList(new[]             {                 new { Id = "A", Name = "Code A" },                 new { Id = "B", Name = "Code B" },                 new { Id = "C", Name = "Code C" },             }, "Id", "Name");             ViewBag.DDLData = result; [HTML]           <select name="ddlT" id="ddlID">                   @foreach (var item in (SelectList)ViewBag.DDLData)           {             <option value="@item.Value" >@item.Text</option>           }         </select>        <sele...

[ASP.NET] Entity Framework 回滾事件

            try             {                 using (TransactionScope ts = new TransactionScope())                 {                     //執行的程式碼                     ts.Complete();                 }                             }             catch (Exception ex)             {                 throw;             } http://www.jiniannet.com/Article/I11409120400347

[ASP.NET] 建立多國語系

ASP.NET使用 Language.resx 檔 在.cs Label1 .Text = Resources. Language .名稱; 在aspx Text='<%$ Resources:Language, 名稱%>' 在js or 網頁中 alert( "<%= Resources.Language.名稱 %>" ); 在MVC 網頁中 @Resources.Language.名稱 < system.web >     < globalization culture = "auto" uiculture = "auto" enableclientbasedculture = "true" > </ globalization ></ system.web > 參考網址 http://marco.easyusing.com/2014/04/aspnet-resourceresx.html

[MVC] CKEditor

//官網下載:http://ckeditor.com/download Nuget 套件管理工具下載:搜尋  HtmlSanitizationLibrary //.cshtml [View]  @using (Html.BeginForm("functionname", "MyBlog", FormMethod.Post, new { id = "FormNew" }))     {  @Html.TextAreaFor(model => model.content, new { id = "content", @name = "content" })  <script type="text/javascript">             CKEDITOR.replace('content', { width: '800px' });  </script> } //MyBlogController.cs [Controller] [HttpPost]     [ValidateInput(false)]      //解決html1編碼問題 public ActionResult functionname(string Title, string content)   //Title,content自動對應到html的id { int RtnCode = m.MyDataEdit(AID, Sanitizer.GetSafeHtmlFragment(Title),Sanitizer.GetSafeHtmlFragment( content)); } 於VS2010就可以透過NuGet幫網站專案安裝上 AntiXSS 程式中使用AntiXSS的 Sanitizer.GetSageHtmlFragement() 方法,取得安全的HTML區段內容。 參考連結: ASP.NET MVC 3 使用 CKEditor 【.NET】防止XSS攻擊 [ config 全部可編輯的T...