Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

how to set select option value as "Y ' from controller to view Select dropdown

$
0
0

I am trying to set the value 'Y' into a select list item from controller. Please can I ask your help to get sorted ? with Many Thanks

I have the following model

EmpDocumentModel
{
[NotMapped]
public string IsClaim { get; set; }
public string Claim { get; set; }
}

I have the controller as given below

public IActionResult GetLicense(EmpDocumentModel data)
        {
            EmpDocumentModel doc = new EmpDocumentModel();
            data.Claim="Test Calim"
            if (data.Claim != null)
            {                data.IsClaim = "Y";  // I am trying to set the value in view only if data.claim is not null
            }
            return Json(data);

        }

My view

 

@model MyModel.Models.EmpDocumentModel<div class="col-md-6"><div class="form-group"><label asp-for="IsClaim" class="control-label control-label-left col-sm-3 text-danger">Any Claim?<br />[If Yes Give Details]</label><div class="controls col-sm-9"><div class="input-group"><div class="input-group-addon"><select id="IsClaim" name="IsClaim" asp-for="IsClaim" data-role="select" >  // I want to set the value as "Y' from controller, if  it is not form-control<option value="N">No</option><option value="Y">Yes</option></select></div><input type="text" name="Claim" class="form-control" id="TxtClaim"  asp-for="Claim" data-role="text" disabled /></div></div></div></div><script>
  function SetLicense() {
    var url = '@Url.Action("GetLicense", "EmpDoc")';$.post(url, $('form').serialize(), function (view) {$("#TxtClaim").val(view.claim);$("#IsClaim").val(view.isclaim);  //is not working 

    });
    }
</script>


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>