Here is the model code
public class viewCase
{
public List<string> lstCategory { get; set; }
public DataTable dtWrkTsk { get; set; }
}
This is the controller code
string query = "SELECT WorkFlowID,Subject,Category FROM CMSTasksWorkFlow"
objcase.dtWrkTsk = objdataclas.ExecuteDataTable(query);
return View("../ViewCases/CasesScreen",objcase);
Below is the cshtml code snippet
function getCaption() {
var cat= $("#layout option:selected").text();
var arr = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(
Model.dtWrkTsk.Select("Catagory='" + cat + "'") ));
}
An error 'cat ' does not exist in current context' is encountered
If trying this approach
function getCaption() {
var cat= $("#layout option:selected").text();
var arr = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(
Model.dtWrkTsk.Select("Catagory='" +@<text> cat </text> + "'") ));}
Error CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type
<div id="addTask" class="modal fade " aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content round">
<div class="modal-header"><h4>New Task </h4></div>
<div id="tbody" class="modal-body" style="height:20%">
@Html.DropDownList("layout", Model.lstCategory.Select(m => new SelectListItem { Text = m, Value = m }), "All", new { onclick = "getCaption()" })
<div id="dtask" style="width: 80%; overflow: scroll; ">
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-primary" >OK</button>
<button type="button" data-dismiss="modal" class="btn">Cancel</button>
</div>
</div>
</div>
</div>
The goal is to keep the datatable disconnected from the server. The getCaption()
function is called whenever the user changes the value in the Html.DropDownList
.
Only the select condition in the datatable needs to be updated based on the JavaScript variable being passed.
How can the JavaScript variable be passed in the datatable.select
function?