Q
Q
Quber2015-05-12 08:32:27
ASP.NET
Quber, 2015-05-12 08:32:27

How to generate two forms with different models in ASP.NET MVC 4?

I'm trying to generate 2 forms, but I can't figure out how to do it. If I get the first form, then I can’t figure out the second one. Forms are filled with different models. But everywhere on the Internet there are examples with only one model. For example,

@model MvcApplication.Models.Post
@model MvcApplication.Models.Category

<form>
    @Html.TextBoxFor(model => model.Title)
</form>
<form>
    @Html.TextBoxFor(model => model.Name)
</form>

I use Title in the Post model, and Name in the Category model. How to make it work I can't figure it out?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bmforce, 2015-05-12
@bmforce

There are many options for solving the problem: stackoverflow.com/questions/4764011/multiple-model...
As the simplest:

@model Tuple<MvcApplication.Models.Post, MvcApplication.Models.Category>

D
dmytrohridin, 2015-05-18
@dmytrohridin

can you do that

public class PostCategoryViewModel
{
public Post Post {get;set;}
public Category Category {get;set;}
}

@model MvcApplication.Models.PostCategoryViewModel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question