Home > Net > ASP MVC Html. BeginForm receptionist pass the entire complex object to background
ASP MVC Html. BeginForm receptionist pass the entire complex object to background
Time:09-18
I passed a strongly typed other action from the background, according to the Model to the front desk and front desk to create a Html BeginForm forms, and through the object routeValues the entire Model back to the background of another action, but contain less than the object inside the complex type data, specific code is as follows:
Model:
Public class FooterViewModel { Public string CompanyName {get; set; }
Public string Year {get; set; } }
Public class BaseViewModel { Public string UserName {get; set; }
Public FooterViewModel FooterData {get; set; } }
Public class OperateEmployeeViewModel: BaseViewModel { Public int ID {get; set; } . . }
View:
@ model MVCExample. ViewModels. OperateEmployeeViewModel
@ { ViewBag. Title="DeleteEmployee"; }
The Delete Confirmation
@ the using (Html. BeginForm (" DeleteEmployee ", "the Employee", Model, FormMethod. Post)) {
First Name:
@ Html. DisplayFor (x=& gt; X.F irstName)
. }
Controller:
Public ActionResult DeleteEmployee (OperateEmployeeViewModel operateEmployee, string BtnSubmit) { The switch (BtnSubmit) { Case "Delete" : The Employee e=new Employee (); . . Return RedirectToAction (" Index "); Case "Cancel" : Return RedirectToAction (" Index "); } Return new EmptyResult (); }
Hit a breakpoint, you can see other action from the background to the front desk of the strong type Model, FooterData data is not null, but from the front desk beginform passed into the background, the action received FooterData is null, excuse me, is this how to return a responsibility, how should solve?
CodePudding user response:
No bosses know? I am of the new, please comment,
CodePudding user response:
Do you have any [HttpPost] controller to delete the above