Hi nauna,
Check this example. Now please take its reference and correct your code.
I have create a common ViewModel that will hold the properties of viewmodel1 and viewmodel2.
Model
viewmodel1
public class viewmodel1
{
public int model1id { get; set; }
}
viewmodel2
public class viewmodel2
{
public int model2id { get; set; }
}
ViewModel
public class ViewModel
{
public viewmodel1 model1 { get; set; }
public viewmodel2 model2 { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Create(ViewModel model)
{
return View("Index");
}
}
View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<_Multiple_ViewModel_MVC.Models.ViewModel>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Index</title>
</head>
<body>
<div>
<%using (Html.BeginForm("Create", "Home", FormMethod.Post))
{%>
<table>
<tr>
<td>Id 1</td>
<td><%:Html.TextBoxFor(x=>x.model1.model1id) %></td>
</tr>
<tr>
<td>Id 2</td>
<td><%:Html.TextBoxFor(x => x.model2.model2id)%></td>
</tr>
</table>
<br />
<input type="submit" value="Create" />
<%} %>
</div>
</body>
</html>
Screenshot
The Form
Values in Controller