Home > Software engineering >  ASP.Net Core How to set value to input
ASP.Net Core How to set value to input

Time:12-13

I'm confused about how to place values in a text form.

I created a simple form.

test.cshtml

@@Model.Name is @Model.Name

<form method=post>
    Name:<input asp-for="Name" />
    <button asp-page="test">Submit</button>
</form>

test.cshtml.cs is

[BindProperty(SupportsGet = true)]
public string Name { get; set; }

public IActionResult OnGet()
{
    Name = "value-get";
    return Page();
}

public IActionResult OnPost()
{
    Name = "value-post";
    return Page();
}

first get result is

@Model.Name is value-get
Name:[value-get] [submit]

enter image description here

  • Related