I have a Javascript function inside a View in a ASP.NET MVC web application.
The Model being passed in my page is a list.
@model IEnumerable<DeliveryDashboard.Models.LeaveDetailsModel>
The Javascript function looks like this:
function ShowLeavePopup(ParameterEmpID) {
var selecteddates = @Model.Where(i => i.EmpID == ParameterEmpID).Select(c => c.ExistingLeaveString).FirstOrDefault();
alert(selecteddates);
// do stuff with the selecteddates
}
This code does not work. The model property which I am trying to retrieve is a simple string data.
If I hard code the data in the lambda expression, then it works. But how to make it read the parameter from the javascript method signature?
var selecteddates = "@Model.Where(i => i.EmpID == 112233).Select(c => c.ExistingLeaveString).FirstOrDefault();
alert(selecteddates)"
I can always do an Ajax call and postback to the server to get the data from database. But since the data I need is already available in the Model List, Is it possible to somehow extract the data from the model itself?