I am trying to pass custom parameter(@item.CompanyId) to editable function and tried lots of things. I am looping in a model and need to pass 2 parameters. id parameter seems OK. But could not pass the CompanyID..
@foreach (var item in Model)
{
<div class="edit" data-rel="@item.CompanyId" id="@item.Id">@Html.DisplayFor(modelItem => item.AnswerText)</div>
}
<script>
$(document).ready(function () {
$(".edit").editable("/Profile/SaveMyAnswer",
{
id: "answerId",
submitdata : {
CompanyId: function () {
return $(this).attr('rel');
}
}
});
});
</script>
I have solved like below.
I have added a name attribute which contains my CompanyId,
<div class="items" name="@item.CompanyId" id="@item.Id">@Html.DisplayFor(modelItem => item.AnswerText)</div>
Change the script as below
$(document).ready(function () { $(".items").each(function () {
var selectedCompanyId = $(this).attr("name");
$(this).editable('/Profile/SaveMyAnswer', {
id : 'answerId',
name : 'answerText',
submitdata: function () {
return { CompanyId: selectedCompanyId };
}
});
});
});