2014-10-18 68 views

回答

0

我對第一個問題的答案。 您必須在「Session [data]」中存儲一些有用的數據,並且不要從客戶端發送它。

public ActionResult Index() 
    { 
     try 
     { 
      if (WebSecurity.IsAuthenticated) 
      { 
       String ContractID_string = Session["ContractID"].ToString(); 
       if(ContractID_string!="0") 

另外,不要在linq或sqlQuery中使用客戶端的一些字符串輸入值而不進行檢查。

的最佳方式使用

控制

[HttpPost] 
    [ValidateAntiForgeryToken] 
public ActionResult _SaveMail(Email_Options Mail) 

鑑於

 @using (Ajax.BeginForm("_SaveMail", "Contract", Model, 
     new AjaxOptions 
     { 
      UpdateTargetId = "Email_Options", 
      OnFailure = "alert('errr')", 
      OnSuccess = "DeleteErrorMessage('#Form_"+ViewBag.Contract_part+"')" 
     }, htmlAttributes: new { id = "Form_"+ViewBag.Contract_part})) 
    { 
     @Html.AntiForgeryToken() 
     @Html.ValidationSummary() 
     <table id="Email_Options"> 
      <tbody> 
       <tr> 
        <th>@Html.LabelFor(m => Model.Email, new { style = "font-size:1.05em;" })</th> 
        <th> 
         @Html.HiddenFor(m => Model.ContractID) 
         @Html.EditorFor(m => Model.Email) 
         @Html.ValidationMessageFor(m => Model.Email) 
         <button style="font-size:1em; margin:0px; padding:0;" type="submit">Сохранить</button> 
        </th> 
       </tr> 
       <tr> 
        <th>@Html.LabelFor(m => Model.SendToEmail, new { @class = "checkbox" })</th> 
        <th>@Html.CheckBoxFor(m => Model.SendToEmail)</th> 
       </tr> 
       <tr> 
        <th>@Html.LabelFor(m => Model.SentToHome, new { @class = "checkbox" })</th> 
        <th>@Html.CheckBoxFor(m => Model.SentToHome)</th> 
       </tr> 
       <tr> 
        <th>@Html.LabelFor(m => Model.Print, new { @class = "checkbox" })</th> 
        <th>@Html.CheckBoxFor(m => Model.Print)</th> 
       </tr> 
      </tbody> 
     </table> 
    }