logo
down
shadow

ViewModel in postback to controller is null


ViewModel in postback to controller is null

By : user2949661
Date : November 17 2020, 01:00 AM
may help you . When you have ViewModels with complex types... you need to call the default Constructor of the complex properties.
code :
public class RegisterUserViewModel
{

    public RegisterUserViewModel() {
        User = new UserDB();
        UsersDetaile = new UsersDetaile();
    }

    public UserDB User { get; set; }

    public UsersDetaile UsersDetaile { get; set; }

    public IEnumerable<state> state { get; set; }
}


Share : facebook icon twitter icon
ASP ViewModel from controller (the Model not model => model.FieldName) became null when postback to controller action

ASP ViewModel from controller (the Model not model => model.FieldName) became null when postback to controller action


By : Bartosz Sakowicz
Date : March 29 2020, 07:55 AM
wish of those help 1 Why do I get a NRE?
I'm guessing, but your reference to 'PostBack' might mean that you come from a WebForms background. In MVC, controller actions must always return the FULL state required to render the view (e.g. in the ViewModel), even after a POST:
code :
[HttpPost]
ActionResult Create(DeliveryRequestViewModel someModel)
{
   //  Do something
   return View("SomeView", someModel); <-- Remember to pass the ViewModel again
}
<%: Html.EditorFor(model => model.Address) %>
Html.EditorFor(foo => foo.Address)
viewmodel returns null on postback mvc 5

viewmodel returns null on postback mvc 5


By : Lucidity
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further It is because you have a property on your model called projectEvent and you refer to your model as projectEvent when it is passed back into the controller.
Change
code :
public ActionResult AddEditEvent(EventViewModel projectEvent)
public ActionResult AddEditEvent(EventViewModel model)
MVC ViewModel collection null on postback

MVC ViewModel collection null on postback


By : Jason Shepherd
Date : March 29 2020, 07:55 AM
This might help you That's because Types just holds the list of options, and the actual options themselves will never be posted back. You need a property like:
code :
public List<int> SelectedTypes { get; set; }
@Html.ListBoxFor(m => m.SelectedTypes, Model.Types)
MVC: unable to postback ViewModel to controller

MVC: unable to postback ViewModel to controller


By : Nitish Naik
Date : March 29 2020, 07:55 AM
With these it helps Below is my view-model , You need to replace
code :
@Html.Partial("_PartialView", Model.modelB)
@Html.EditorFor(m => m.modelB)
/Views/Shared/EditorTemplates/ModelB.cshtml
<input name="Name1" ... />
<input name="modelB.Name1" ... />
MVC ViewModel collections are null on postback

MVC ViewModel collections are null on postback


By : henri83
Date : March 29 2020, 07:55 AM
wish of those help First of all, by specifying the attribute Bind(Include = "BuildingType") you're telling MVC to only bind this single property. Remove the attribute, and MVC will try to bind your 2 IEnumerable collections.
Next, check your @Html.EditorFor calls. I'm not sure MVC can understand FirstOrDefault inside. Try avoiding LINQ selectors inside your view.
Related Posts Related Posts :
  • Ninject dependency injection: Read bindings from config?
  • Creating Custom Authorization Attribute with MVC
  • How to use c# inside mvc razor pages
  • Reasons not to increase maxQueryStringLength?
  • asp.net mvc exclude an action from search engine crawling
  • Best Way to reuse code inside my Controller action method
  • BEM and asp.net mvc
  • RazorPDF save pdf file to server directory in MVC4
  • Controller Unit Testing with model validation
  • How to bind input field to editfor model MVC
  • How can I restrict access to a view only to two specific users each time in MVC?
  • How to modify CRUD operations with Entity Framework in .NET MVC application
  • ModelBinding Issue with a Struct
  • issue in adding elements into a list in mvc
  • IActionFilter class can only find physical attributes, not ones added in GlobalFilters config
  • ASP.NET MVC Bug with Model Binding: "Specified cast is not valid" when no data provided for dictionary
  • How to reuse class in models without using validation for all of them
  • How to set routing to have some controller actions handled by angular
  • ads while debugging mvc website
  • Does editing a Web.config file trigger an overlapping recycle or a start+stop of the application pool?
  • How can i delete multi selected records using checkbox in Kendo Grid?
  • 404.15 not found MVC4 RazorJS
  • Passing selected value from the radio buttons to the controller in MVC
  • TFS:The "Microsoft.Reporting.RdlCompile" task could not be loaded from the assembly Microsoft.ReportViewer.Web
  • Get the user id of a username identity 2.0
  • Don't validate date fields on MVC
  • Add class and default value to MVC dropdown that isn't linked to model
  • Passing values from the view to the controller in MVC
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org