Reputation: 77
I have this in my viewModel.
public IEnumerable<TeamDto> Teams { get; set; }
And, in my view:
<input name="Teams" id="Teams" [email protected] />
How do I access the team list in jQuery?
var data2 = $("#Teams")??
Upvotes: 0
Views: 488
Reputation: 155
Use the below code on the same cshtml page in end of page.
@{
IEnumerable<TeamDto> loRes = new IEnumerable<TeamDto>();
loRes = Model.Teams;
<script>
console.log('@loRes.FirstOrDefault().fiedlName');
</script>
}
Upvotes: 1
Reputation: 2813
You access the value of an input by using the val()
method. You can also set the value with val('your value')
var data2 = $("#Teams").val();
Upvotes: 1