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))
{





.
}

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

CodePudding user response:

The
reference 2 floor 姎 jacaranda response:
do you have any [HttpPost] controller to delete the above


Added, still no

CodePudding user response:

reference wuzhiwei2012 reply: 3/f
Quote: refer to the second floor 姎 jacaranda response:

Do you have any [HttpPost] controller to delete the above


Added, still no

I also contacted the MVC, you at the front desk is the method of how to trigger the controller, if the submit button, if not have any parameter named

CodePudding user response:

reference 4 floor 姎 jacaranda response:
Quote: reference wuzhiwei2012 reply: 3/f

Quote: refer to the second floor 姎 jacaranda response:

Do you have any [HttpPost] controller to delete the above


Added, still no

I also contacted the MVC, you at the front desk is the method of how to trigger the controller, if the submit button, if not have any parameter named

Yes, in the Html. Beginform a submit button,

CodePudding user response:

reference 5 floor wuzhiwei2012 reply:
Quote: refer to 4th floor 姎 jacaranda response:

Quote: refer to the third floor wuzhiwei2012 response:

Quote: refer to the second floor 姎 jacaranda response:

Do you have any [HttpPost] controller to delete the above


Added, still no

I also contacted the MVC, you at the front desk is the method of how to trigger the controller, if the submit button, if not have any parameter named

Yes, in the Html. Beginform a submit button,

You directly write Html. Beginform try ()

CodePudding user response:

refer to the eighth floor 姎 jacaranda response:
Quote: refer to the fifth floor wuzhiwei2012 reply:

The
Quote: reference 4 floor 姎 jacaranda response:

Quote: refer to the third floor wuzhiwei2012 response:

Quote: refer to the second floor 姎 jacaranda response:

Do you have any [HttpPost] controller to delete the above


Added, still no

I also contacted the MVC, you at the front desk is the method of how to trigger the controller, if the submit button, if not have any parameter named

Yes, in the Html. Beginform a submit button,

You directly write Html. Beginform try ()

No good, if the Html Beginform () with no arguments, even the most basic values are not passed,

CodePudding user response:

Taiwan before and after Model class field name, type the same

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related

First Name:

@ Html. DisplayFor (x=& gt; X.F irstName)