如何使用jQuery在模型上获取属性Speaks tuff的值?

How to get value of property Speaks tuff on Model using jQuery?

提问人:ahmed abdelaziz 提问时间:11/16/2023 最后编辑:ahmed abdelaziz 更新时间:11/16/2023 访问量:16

问:

我在 asp.net MVC 5 .NET Framework 上工作。我遇到了问题,我无法获得价值 属性 SpeakStuff 当捕获 Detail 操作结果时。

on 对象属性由两个复选框 Yes 和 No 表示。ResignationRequesterSpeakStuff

如果等于 True,则将选中 Yes 复选框SpeakStuff

如果等于 False,则不会选中 No 复选框SpeakStuff

那么在捕获详细操作结果时如何做到这一点

我的代码如下:

<div> 
@Html.Label("Did You Meet/Speak to Staff", htmlAttributes: new { @class = "control-label col-md-5" })
  <div class="col-md-7">
      <input type="checkbox" id="SpeakStuff" name="SpeakStuff" value="true" class="speak-stuff-checkbox" @(Model.SpeakStuff ? "checked" : "") />
      Yes
      &nbsp;&nbsp;
      <input type="checkbox" id="SpeakStuff" name="SpeakStuff" value="false" class="speak-stuff-checkbox" @(!Model.SpeakStuff ? "checked" : "") />
      No
  </div>
</div>

 $('.speak-stuff-checkbox').on('change', function () {
     $('.speak-stuff-checkbox').not(this).prop('checked', false);
     var selectedValue = $(this).val();
     $('#SpeakStuff').val(selectedValue);
 });
  public class ResignationRequester
  {

   public bool SpeakStuff { get; set; }
  }
[HttpGet]
public async Task<ActionResult> Details(int? id, string msg)
{
  
    ResignationRequester workforceRequest = Workforce.ResignationGetRequestByID((int)id);
   
   //when check workforceRequest.SpeakStuff it will be true or false 
// so How to make check box yes checked when true and checkbox No checked when it False
    return View(workforceRequest);
}

所以假设那么 No will check 如下图所示:workforceRequest.SpeakStuff=falseimage for checkbox checked

javascript jquery asp.net-web-api html-helper

评论


答: 暂无答案