Request context
The DotvvmViewModelBase class defines the Context property which provides access to various DotVVM and ASP.NET resources, like ASP.NET Core or OWIN HTTP context etc. You can also make redirects, return files, and more.
Request information
IsPostBackproperty determines whether the current request is postback, or whether the page is loaded for the first time.Parametersproperty is a dictionary which contains values of the route parameters.Queryproperty is a dictionary which contains parameters from the URL query string.HttpContextproperty gives you access to the OWIN or ASP.NET context of the current request. It's useful when you need to work with cookies, authentication etc. This property exposes a common interface overOwinContextandHttpContextfrom ASP.NET Core. Not all features are available in this abstraction because of the differences between the two platforms.GetAspNetCoreContext()is an extension method which you can use in the ASP.NET Core version to access the ASP.NET CoreHttpContext.GetOwinContext()is an extension method which you can use in the OWIN version. It returns the realOwinContext.
Validation
ModelStateproperty represents the state of the model validation. You can report validation errors to the UI using this object'sAddModelErrormethod, or you can use theIsValidproperty to determine whether there are any validation errors in the page.- The
FailOnInvalidModelStatemethod checks the validity of the viewmodel and throws an exception if the viewmodel is not valid. The request execution is interrupted and the validation errors are displayed in the client's browser (e.g. in the ValidationSummary control).
Redirects
RedirectToRouteandRedirectToRoutePermanentmethods redirect the user to the specified route and allows to supply route parameters. The request execution is interrupted by this call.RedirectToLocalUrlmethod redirects the user to the specified URL and makes sure that the URL is not an absolute URL pointing to a different site. The request execution is interrupted by this call.RedirectToUrlandRedirectToUrlPermanentmethods redirect the user to the specified URL. The request execution is interrupted by this call.
Returning files
ReturnFileAsyncfunction is used when you need to return a file which will be downloaded by the user.IncludeReturnedFileAsyncfunction stores a file for download without interrupting the current command or static command. The current request can still finish normally and update the viewmodel.
Asynchronous operations
- Use
RequestAbortedas the cancellation token for all asynchronous operations.GetCancellationToken()is obsolete, it served the same purpose in older versions.
URL manipulation
TranslateVirtualPathmethod can translate URLs from the~/some/pathnotation to the domain-relative URLs (e. g./appVirtualDirectory/some/path). This is useful if your application supports running in a virtual directory.