ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Pass multiple Models from one View to Controller in ASP.Net MVC<p>Hi&nbsp;<a class="username" rel="nauna">nauna</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p>I have create&nbsp;a common ViewModel that will hold the properties of&nbsp;viewmodel1 and&nbsp;viewmodel2.</p> <p><strong><span style="text-decoration: underline;">Model</span></strong></p> <p><strong>viewmodel1</strong></p> <pre class="brush: csharp">public class viewmodel1 { public int model1id { get; set; } }</pre> <p><strong>viewmodel2</strong></p> <pre class="brush: csharp">public class viewmodel2 { public int model2id { get; set; } }</pre> <p><strong>ViewModel</strong></p> <pre class="brush: csharp">public class ViewModel { public viewmodel1 model1 { get; set; } public viewmodel2 model2 { get; set; } }</pre> <p><strong><span style="text-decoration: underline;">Controller</span></strong></p> <pre class="brush: csharp">public class HomeController : Controller { // GET: /Home/ public ActionResult Index() { return View(); } [HttpPost] public ActionResult Create(ViewModel model) { return View(&#34;Index&#34;); } }</pre> <p><strong><span style="text-decoration: underline;">View</span></strong></p> <pre class="brush: html">&lt;%@ Page Language=&#34;C#&#34; Inherits=&#34;System.Web.Mvc.ViewPage&lt;_Multiple_ViewModel_MVC.Models.ViewModel&gt;&#34; %&gt; &lt;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&gt; &lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;Index&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;%using (Html.BeginForm(&#34;Create&#34;, &#34;Home&#34;, FormMethod.Post)) {%&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Id 1&lt;/td&gt; &lt;td&gt;&lt;%:Html.TextBoxFor(x=&gt;x.model1.model1id) %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Id 2&lt;/td&gt; &lt;td&gt;&lt;%:Html.TextBoxFor(x =&gt; x.model2.model2id)%&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br /&gt; &lt;input type=&#34;submit&#34; value=&#34;Create&#34; /&gt; &lt;%} %&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><span style="text-decoration: underline;">The Form</span></p> <p><span style="text-decoration: underline;"><img src="https://i.imgur.com/Jee9M7D.jpg" alt="" width="248" height="167" /></span></p> <p><span style="text-decoration: underline;">Values in Controller</span></p> <p><span style="text-decoration: underline;"><img src="https://i.imgur.com/NbPs7ZF.jpg" alt="" width="357" height="88" /></span></p>https://www.aspforums.net:443/Threads/821321/Pass-multiple-Models-from-one-View-to-Controller-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/821321/Pass-multiple-Models-from-one-View-to-Controller-in-ASPNet-MVC/Wed, 12 Jun 2019 05:36:32 GMT