ASP.Net MVC reusable form like RenderAction or RenderPartial

I am looking for best practice for embedding a multiple page form as a partial presentation.

I have a contact form that I want to implement on several pages of the site. Typically, the form will be on the contact page, and the contact model can be a model for presentation and use data annotations for validation. However, the view is already strongly typed.

How to create a reusable form in partial view and paste it on the page? I use N2 on the site, so the pages already have a strongly typed model, but I would be open to expanding these objects.

+3
source share
2 answers

Personally, I recommend using for Html.RenderAction () for cross-cutting issues like these.

Your contact form handler must exist regardless of the page you are currently viewing, so you have three options:

  • Manually add it to the response of the current action.
  • Manually add it to the response of the current controller through a base controller that modifies the ViewState or ViewModel
  • Call RenderAction () HtmlHelper inside the current view

3 , , 1 2 ( ), . RenderAction(), , , .

+4

RenderPartial, , RenderAction ( ).

0

Source: https://habr.com/ru/post/1760857/


All Articles