Sunday, August 26, 2018

trying to prepopulate a select input using .NET Core ASP Pages

First off, I am sorry if this is not the right place for tech support questions. I am not seeing anywhere on the side panel that lists the subreddit rules.

So I have a statement like this.

<select asp-for="@Model.Answers[answerOptionIndex].AnswerText" asp-items="@Model.PremiumRateTypeOptionSelectListItems" class="form-control"> 

Where asp-items is generating from a SelectListItem. And as of right now it produces this.

<select name="Answers[1].AnswerText" class="form-control valid" id="Answers_1__AnswerText" aria-invalid="false"> 

And we already used that name and ID in several places in AJAX so we would prefer not to change asp-for.

What I discovered though is now that I want to edit it wants me to put the variable for the value its going to be in asp-for; in my case "answerTextForQuestion". I put that in for asp-for and click edit and when the page loads it does indeed pre-populate that dropdown but then it breaks all the AJAX functionality because the edit changed that variable changes as it goes through a switch statement but now all of my dropdowns all have the id = answerTextForQuestion... which is bad.

What I need is just the ability to tell the select statement that the preselected value is answerTextForQuestion, but without changing the ID or name (so not use asp-for).

trying to prepopulate a select input using .NET Core ASP Pages Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team