C
C#3mo ago
Ayin

How things get to the place

I have found this one thing by Microsoft that confused me so much
public async Task<IActionResult> OnPostTryValidateAsync()
{
var modifiedReleaseDate = DateTime.Now.Date;
Movie.ReleaseDate = modifiedReleaseDate;

ModelState.ClearValidationState(nameof(Movie));
if (!TryValidateModel(Movie, nameof(Movie)))
{
return Page();
}

_context.Movies.Add(Movie);
await _context.SaveChangesAsync();

return RedirectToPage("./Index");
}
public async Task<IActionResult> OnPostTryValidateAsync()
{
var modifiedReleaseDate = DateTime.Now.Date;
Movie.ReleaseDate = modifiedReleaseDate;

ModelState.ClearValidationState(nameof(Movie));
if (!TryValidateModel(Movie, nameof(Movie)))
{
return Page();
}

_context.Movies.Add(Movie);
await _context.SaveChangesAsync();

return RedirectToPage("./Index");
}
Here, how did we get object of Movie? Method doesn't have any aprameters so I simply cannot get it
6 Replies
Ayin
Ayin3mo ago
Doesn't it need something like ([FromForm] Movie movie) to get model?
canton7
canton73mo ago
Some context would be good. It's probably a property, but hard to say for sure without more info
Ayin
Ayin3mo ago
Are controllers supposed to have properties? Other than services and configs
Saber
Saber3mo ago
that specific example would be razor pages so its not a controller
Ayin
Ayin3mo ago
So I would still need [FromForm] to use ModelState in controller
Want results from more Discord servers?
Add your server
More Posts
Visual code studio and msbuildim currently having problems while scripting apparently when i press (Run Build Task) im getting thiMediatR - System.Text.Json.JsonException: 'S' is an invalid start of a value.I have a project with Clean Architecture and MediatR. My API gets the request fine and the command Blazor, auto unsubscribe patternI have created website using blazor, and if some component subscribe to something then it implement ✅ Form1.resx file gives error on Internet or Restricted zoneForm1.resx file gives error on Internet or Restricted zone I can't fix it error (english):Severity LHelp with API structureI want to create modular API structure https://timdeschryver.dev/blog/maybe-its-time-to-rethink-our-✅ WPF - how to correctly call a method in the ViewModel when an event occurs in the View?I want to call a method in the ViewModel when an event happens in the View. That is, when the View Blazor help needed. How can i Validate datalist entries in a child componentI have written a Blazor testapp that has an EditForm with a child component in the parent component.Inlcude content after run a command (.csproj)Hey i wanna ask if it would possible to place this after the cmake building command? ```cs <IteOpinion on the code i've writtenHello, I have a discord bot im working on, the code i am about to show reads a JSON Config file. I w✅ Receiving Input While Minimized (WinForms C#)Pretty general question here. How would I go about receiving input from my user while they aren't t