# Mvc

This part provides methods for working with ViewEngine and other common MVC stuff.

## AjaxAttribute

`AjaxAttribute` allows to block non-ajax requests to marked controllers or actions.

## Controller extensions

| Method name            | Return type    | Description                                  |
| ---------------------- | -------------- | -------------------------------------------- |
| RenderPartialViewAsync | `Task<string>` | Renders a partial view using provided model. |
| RenderViewAsync        | `Task<string>` | Renders a view using provided model.         |

Sample usage is provided below:

```csharp
public async Task<IActionResult> DoSomething(int id, string name)
{
    var model = new CustomViewModel { Id = id, Name = name };
    var result = await this.RenderPartialViewAsync("_CustomPartialView", model);
    return Content(result); // This returns string with rendered partial view.
}
```

## ITempDataDictionary extensions

This extension methods help to work with `ITempDataDictionary`:

| Method name | Return type | Description                                                                                                        |
| ----------- | ----------- | ------------------------------------------------------------------------------------------------------------------ |
| Put         | `void`      | Places a specified object in current `ITempDataDictionary` serializing it. Overwrites an existing value if needed. |
| Peek        | `T`         | Get object for specified key from current `ITempDataDictionary`.                                                   |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.structr.dev/presentation/aspnetcore/mvc.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
