Heavily printed views - add additional data using the edit / create form

I have a simple (hopefully) scenario.

  • Seat table
  • Computer table
  • SeatComputers table (since a seat can have multiple computers)

I have a strongly typed Change view for the Seat. I managed to get a list with several choices on this page for assigning or unassigning computers (jquery for adding / removing items).

However, when I submit the form, the contents of the select list are not sent to the controller action.

I assume this is because the selected list of “computers” is not a property of the model.

Is there anyway POST additional data for the controller outside the model properties?

My tables look something like this: alt text

+3
source share
2 answers

You do not need to publish this list, because it is already stored in the database, and you even have a repository to retrieve it, right? Therefore, the only thing that needs to be published is the choice of the user, since this is the only thing you do not know. In the POST action, restore the list in your view model using the repository, just as you did in the GET action that displayed the form.

Anyway, is there POST extra data for the controller outside the model property?

Of course, just include them as input fields so that their values ​​are sent via POST and into your controller action:

[HttpPost]
public ActionResult Index(SomeViewModel model, string param1, string, param2)
{
    ...
}

: .

+3

ViewModels, Entity, , , Visual Studio .

System.Web.Mvc.ViewPage<Seats> System.Web.Mvc.ViewPage<SeatEditorViewModel>

, , , .

0

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


All Articles