I'm using a script in the Edit template of the datagrid so that when you click the Add button it fires and does some things on the newly inserted row. However I am noticing that when I get the prefixed Id for an item it is getting the wrong row Id.
It seems to be 1 above what it should be.
As an example I want to focus the first item in a grid when you click Add.
I put this script in the edit template:
However it doesn't work. If however I do some code to get the prior row id it does.
var id = '@Html.PrefixedId(m => m.Portfolio)'.match(/[0-9]/) * 1 - 1;
$('#PortfolioAllocations___' + id + '___Item_Value_Portfolio').focus();
But this means I have to hard code in the link.
Is there any reason why what I'm doing isn't working?