I have an ASP.NET MVC application with a model which is bound to a view. I want to view the manipulated data immediately without Javascript or postback. Is this possible?
In "current count" below it always shows zero.
My model:
public class CounterModel
{
public int Number { get; set; }
}
My view (Counter.cshtml
):
@model CounterModel
<h4>Counter</h4>
<p role="status">Current count: @Model.Number</p>
<input type="number" class="form-control" asp-for="Number" />
My controller (HomeController.cs
):
public IActionResult Counter()
{
CounterModel model = new() { Number = 0 };
return View(model);
}
Result:
The ASP.NET MVC framework only returns HTML and provides no interactivity between the data models and the UI, without javascript / POSTs etc.
If you're looking for a framework that does provide this and allows you make bindings between UI elements and models, look into Blazor.
https://dotnet.microsoft.com/en-us/learn/aspnet/blazor-tutorial/intro