2015-06-08 42 views
0

我有問題。從下面的圖片中,我只需點擊VERIFIED BUTTON,就可以將狀態從CREATED更改爲VERIFIED。我不想單擊單選按鈕來編輯它。我想通過使用「驗證」按鈕來編輯值。謝謝。目前,要編輯狀態,我需要單擊單選按鈕並更改它。我想通過點擊驗證按鈕來改變它。使用按鈕編輯列值,而不是手動輸入

enter image description here

下面

是我的按鈕

   <input type="submit" name="submit" value="Save" class="btn btn-default" /> 
       <input type="submit" name="submit" value="Verified" class="btn btn-default" /> 

以下是我的控制器

public ActionResult Edit(ListOfItems objGetListOfItems) 
     { 
      if (objGetListOfItems == null) 
      { 
       return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
      } 
      ListOfItems LOIEdit = ARSharedDAL.Find(objGetListOfItems); 
      if (LOIEdit == null) 
      { 
       return HttpNotFound(); 
      } 
      return View(LOIEdit); 
     } 

這是它鏈接到存儲過程

public static ListOfItems Find(ListOfItems objGetListOfItems) 
    { // 
     SqlDataReader rdrDataAccess = null; 

     ListOfItems objListOfItems = null; 

     SqlConnection database = new SqlConnection(MyCOODataConn.MyCOOConnectionString); 

     database.Open(); 
     SqlCommand databaseCmd = new SqlCommand("SP_APP_SUI_ListOfItemsDetails", database); 
     databaseCmd.CommandType = CommandType.StoredProcedure; 

     databaseCmd.Parameters.Add(new SqlParameter("@idShared", objGetListOfItems.idshared)); 

     rdrDataAccess = databaseCmd.ExecuteReader(); 

     objListOfItems = new ListOfItems(); 

     while (rdrDataAccess.Read()) 
     { 
      objListOfItems = new ListOfItems(); 

      objListOfItems.idshared = GeneralUtil.GetDBInt(rdrDataAccess, "idshared"); 
      objListOfItems.reftab = GeneralUtil.GetDBString(rdrDataAccess, "reftab", ""); 
      objListOfItems.codeShared = GeneralUtil.GetDBString(rdrDataAccess, "code", ""); 
      objListOfItems.abbreviation = GeneralUtil.GetDBString(rdrDataAccess, "abbreviation", ""); 
      objListOfItems.description = GeneralUtil.GetDBString(rdrDataAccess, "description", ""); 
      objListOfItems.remarks = GeneralUtil.GetDBString(rdrDataAccess, "remarks", ""); 
      objListOfItems.effectivedate = GeneralUtil.GetDBString(rdrDataAccess, "effectivedate", ""); 
      objListOfItems.Status = GeneralUtil.GetDBString(rdrDataAccess, "Status", ""); 


     } 

     return objListOfItems; 
    } 

編輯視圖代碼

@using (Html.BeginForm()) 
{ 
    @Html.AntiForgeryToken() 

    <div class="widgetbox"> 
     <h4 class="widgettitle">Manage Reference Table</h4> 

     <div class="widgetcontent"> 

      <div> 
       @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 
       <table> 
        <tr> 
         <td> 
          @Html.Label("No :", htmlAttributes: new { style = "width: 70px; " }) 
         </td> 
         <td> 
          <div class="col-md-10"> 
           @Html.DisplayFor(model => model.idshared, new { htmlAttributes = new { @class = "form-control" } }) 
          </div> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          <div class="form-group"> 
           @Html.Label("Ref Tab :", htmlAttributes: new { @class = "control-label col-md-2" }) 

          </div> 
         </td> 
         <td> 
          <div class="col-md-10"> 
           @Html.EditorFor(model => model.reftab, new { htmlAttributes = new { @class = "form-control" } }) 
           @Html.ValidationMessageFor(model => model.reftab, "", new { @class = "text-danger" }) 
          </div> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          <div class="form-group"> 
           @Html.Label("Code :", htmlAttributes: new { @class = "control-label col-md-2" }) 

          </div> 
         </td> 
         <td> 
          <div class="col-md-10"> 
           @Html.EditorFor(model => model.codeShared, new { htmlAttributes = new { @class = "form-control" } }) 
           @Html.ValidationMessageFor(model => model.codeShared, "", new { @class = "text-danger" }) 
          </div> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          @Html.Label("Abbreviation :", new { style = "padding-right: 10px; " }) 
         </td> 
         <td> 
          <div class="col-md-10"> 
           @Html.EditorFor(model => model.abbreviation, new { htmlAttributes = new { @class = "form-control" } }) 
           @Html.ValidationMessageFor(model => model.abbreviation, "", new { @class = "text-danger" }) 
          </div> 
         </td> 

        </tr> 
       </table> 

       <table style="text-align:left;"> 
        <tr> 
         <td> 
          @Html.Label("Description :", new { style = "padding-right: 10px; " }) 
         </td> 
         <td> 
          <div class="col-md-10"> 
           @Html.EditorFor(model => model.description, new { style = "width: 150px;" }) 
           @Html.ValidationMessageFor(model => model.description, "", new { @class = "text-danger" }) 
          </div> 
         </td> 
        </tr> 
       </table> 

       <table> 
        <tr> 

         <td> 
          <div class="form-group"> 
           @Html.Label("Remarks :", htmlAttributes: new { @class = "control-label col-md-2" }) 
          </div> 
         </td> 
         <td> 
          <div class="col-md-10"> 
           @Html.EditorFor(model => model.remarks, new { @class = "form-control" }) 
           @Html.ValidationMessageFor(model => model.remarks, "", new { @class = "text-danger" }) 
          </div> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          <div class="form-group"> 
           @Html.Label("Effective Date:", htmlAttributes: new { @class = "control-label col-md-2" }) 
          </div> 
         </td> 
         <td> 
          <div class="col-md-10"> 
           @Html.EditorFor(model => model.effectivedate, new { htmlAttributes = new { @class = "form-control" } }) 
           @Html.ValidationMessageFor(model => model.effectivedate, "", new { @class = "text-danger" }) 
          </div> 
         </td> 

        </tr> 
        <tr> 
         <td> 
          <div class="form-group"> 
           @Html.Label("Status:", htmlAttributes: new { @class = "control-label col-md-2" }) 
          </div> 
         </td> 
         <td> 
          <div class="col-md-10"> 
           @Html.RadioButtonFor(x => x.Status, "CREATED", new { }) CREATED 
           @Html.RadioButtonFor(x => x.Status, "VERIFIED", new { }) VERIFIED 

          </div> 
         </td> 

        </tr> 
       </table> 
       <br /> 

       <div class="col-md-offset-2 col-md-10"> 
        <input type="submit" name="submit" value="Save" class="btn btn-default" /> 
        <input type="submit" name="submit" value="Verified" class="btn btn-default" /> 
       </div> 

      </div> 

     </div> 

    </div> 


} 

<div> 
    @Html.ActionLink("Back to List", "Index") 
</div> 
+0

你能分享整個視圖代碼嗎? –

+0

@MirzaDanishBaig here mirza。 – abcd

+0

你將需要JavaScript來做到這一點。如果您使用jQuery,請使用$ .ajax,並在成功回調函數中使用$('input [value =「CREATED」)。attr('checked','checked'); 也刪除Html.BeginForm() – Irshu

回答

1

寫你的電話後成功處理程序,並把它放進你的成功處理程序

$("input[value='verified']").prop("checked", true); 

Here是一個簡單的小提琴。與此小提琴不同,您可能希望將該代碼置於驗證調用的成功處理程序中,以確保數據實際上是從數據庫驗證的。 另外,如果您不想讓用戶選擇單選按鈕,則可能需要禁用它們。


只是一個建議。但從用戶體驗來看,它看起來更好,如果

  1. 你給一個複選框以顯示數據是否被驗證(驗證:【檢查】)出現
  2. 顯示,上面寫着覈實一些綠色標籤,這數據驗證完成後。
+0

這是非常有用的。謝謝你分享=) – abcd

-1
public ActionResult Edit(ListOfItems objGetListOfItems) 
     { 
      if (objGetListOfItems == null) 
      { 
       return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
      } 
      ListOfItems LOIEdit = ARSharedDAL.Find(objGetListOfItems); 
      if (LOIEdit == null) 
      { 
       return HttpNotFound(); 
      } 
      return View(LOIEdit); 
     } 
+0

是不是我的控制器? – abcd

0

我設法做到了。多謝你們。如果我的問題不清楚,我很抱歉。

我需要的是將狀態從CREATED更改爲VERIFIED而不使用單選按鈕。我做的是,我只是使用jQuery來改變狀態。而不是使用單選按鈕,我創建了一個隱藏文本框,其值將爲'VERIFIED'。一旦VERIFIED按鈕被點擊,它將攜帶「VERIFIED」值。下面是我的隱藏文本框和jQuery代碼

<div class="col-md-10" hidden> 

     @Html.TextBoxFor(m => m.Status, new { id = "Statusd", name = "Testname1" }) 
     @Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" }) 




</div> 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
<script> 
    $(document).ready(function(){ 
     $("#Verified").click(function(){ 
      $('#Statusd').val('ENDORSED'); 
     }); 
    }); 
</script> 

非常感謝你的時間夥計。

+0

如果它是一個布爾字段,我會建議使用隱藏的複選框。將其代碼用於其他團隊成員可能會令人困惑,並且處理字符串中的狀態總是有風險的,因爲小的拼寫錯誤會導致嚴重問題。 – shwetaOnStack

+0

@shwetaOnStack我在想同樣的事情。不好把這件事提交給團隊。謝謝指出。 =) – abcd

相關問題