Posting to another model from a form in ASP.NET MVC

后端 未结 5 1372
旧时难觅i
旧时难觅i 2021-02-13 15:44

If I have a view that has a model, lets say Car..

@model Project.Car

inside that view I want to create a form that sends data to a new model

5条回答
  •  花落未央
    2021-02-13 16:13

    Your view is set up to use a model of type Project.Car however your action method takes a model of type ViewModels.NewModel, but also your model class posted is of type Add?

    Change them all to match (assuming Add is correct):

    View:

    @model Add
    

    Controller:

    [HttpPost]
    public PartialViewResult Add(Add model)
    

提交回复
热议问题