what happens behind model passing in ASP MVC4

后端 未结 2 1269
闹比i
闹比i 2021-01-25 20:50

Learning the ASP MVC now, just my 3rd week on MVC

I did some tests on modeling pass, basically the controller just get the model, and pass into the view without doing an

相关标签:
2条回答
  • 2021-01-25 20:55

    You need to have getter and setter for ViewModel in order to retrieve the values from posted form.

    public class ViewModel
    {
        public string str1 { get; set; }
        public string str2 { get; set; }
        public List<int> list { get; set; }
    }
    
    0 讨论(0)
  • 2021-01-25 21:07

    You are showing us the POST-version of the method. Usually, the post action method would take the model, do some kind of processing (input validation, save to db, call a service, etc.), then if success, redirect to a different page.

    You would usually only call the view from the POST action method if you have any problems with the inputs that require the user to fix.

    0 讨论(0)
提交回复
热议问题