In Razor View how to access the Id of dynamically created number of textbox -
i trying create number of text box dynamically in razor view. how can ensure different id assigned each of text box dynamically? objective access numeric value entered in dynamic textbox (questioncount) , calculate sum of values entered.
below part of code used in view.
@foreach (var qp_count in viewbag.nonuniformtempcount) { var str = @viewbag.nonuniformtempnames[tempindex]; <b>@str</b> (int qcount = 1; qcount <= qp_count; qcount++) { **<br /> <b>@qcount</b> <b>@html.textbox("questioncount")</b>** } tempindex++; }
in order give different id's dynamicaly generated textboxes try :-
@foreach (var qp_count in viewbag.nonuniformtempcount) { var str = @viewbag.nonuniformtempnames[tempindex]; <b>@str</b> (int qcount = 1; qcount <= qp_count; qcount++) { <br /> <b>@qcount</b> <b>@html.textbox("questioncount",null,new{ id = "question-" + @qcount + @qp_count })</b> } tempindex++; }
Comments
Post a Comment