Data in the partial view depends on the user selection and I need to set the values of the model based on that.
<ul class="list-group list-group-flush">
@{ int i = 0; }
@foreach (var task in Model.Tasks.Where(x => x.IsCompleted == false))
{
<li class="list-group-item list-group-item-action" onclick="openCurrentTaskModal(@task)">
@task.Title
<form method="post" id="formCompleteTask[@i]" asp-action="Complete" asp-controller="Task">
<input type="hidden" name="taskId" value="@task.Id" />
<input type="hidden" name="projectGuid" value="@Model.Guid" />
</form>
<a onclick="document.getElementById('formCompleteTask[@i]').submit();">
<img src="~/img/circle.svg" alt="Complete" />
</a>
</li>
i++;
}
</ul>
<partial name="~/Views/Task/_CurrentTaskModalPartial.cshtml" model="new Taskly.Web.ViewModels.TaskViewModel()"/>
I want to populate the created view model with this function:
<script>
function openCurrentTaskModal() {
//set task parameter to view model
$('#currentTaskModal').modal('show');
}
</script>