I need to dynamically assign the index of each razor model through javascript.
Here is the javascript
function ResetIndexModel() {
var idx = 0;
$('.page-name').each(function () {
var text = $(this).text();
text = text.replace('Model.DraftPages[#].Name', 'Model.DraftPages[' + idx + '].Name');
$(this).text(text);
idx++;
});
}
and this is my HTML
<li class="active tabPage"><label for="Name" class="page-name">Model.DraftPages[#].Name</label><span title="Edit Page Name" class="glyphicon glyphicon-pencil" style="font-size:10px;"></span>></li>
I have also tried this.
text = text.replace('Model.DraftPages[#].Name', '@('@')Model.DraftPages[' + idx + '].Name');
so I need to replace the '#' symbol using the iteration from the js function. With my current code, it will only display 'Model.DraftPages[0].Name' in the label.
My expectation is, it supposed to display the value of @Model.DraftPages[0].Name
Is there any way I can achieve this?