Hi @Blooming Developer ,
How can i display the first name and last name?I tried the ajax calling,but its showing undefined error.
when i clcik the close icon its showing Uncaught refrence error
From your description and the code in the create page, you want to show/select/delete the tag with the username and email. Based on this scenario, I created another sample, you could refer to it:
create a view model which contains the full name and the email address:
public class ExistTags
{
public string Name { get; set; } //name: firstName + " " + lastName
public string Email { get; set; } //email address
}
[Note] This model is used to display the selected tags in the view page. You can also add it as a database field.
In the Form.cshtml.cs page OnGet
method: this time we use the ViewData to bind the exist selected tags
public void OnGet()
{
//RequestFormMaster = new RequestFormModel()
//{
// ExistTags = "******@hotmail.com,******@hotmail.com"
//};
// you can query the database and get the selected tag and the related email.
var existtags = new List<ExistTags>()
{
new ExistTags(){ Name="Teena John", Email = "******@mail.com"},
new ExistTags(){ Name="David Smith", Email = "******@mail.com"}
};
//required using System.Text.Json;
//convert the object to json string, then we can store it in the hidden field.
var jsonstring = JsonSerializer.Serialize(existtags);
//use ViewData to transfer data.
ViewData["existtag"] = jsonstring;
}
Code in the Form.cshtml: check the hidden field, and the style tag is used to add spacing between the select tags.
You can view the page source from here: 152851-formcshtml.txt
After page load, the hidden field looks like this:
The debug output is like this:
[Note] There might have a question: in the above sample, after editing, the selected tag was stored in the alltags
array, so when you submit the form to save change. You might need to get the selected tag from the alltags
array. Or when you add the tag element, you could add the name attribute, then when submitting the form to the Post method, you can get the value via the name attribute.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion