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 Table Row values from View to Controller on Button Click in ASP.Net MVC<p>Hi&nbsp;NerakSeven,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">Database</span></strong></p> <p>For this example&nbsp;I have made use of the following table Customers with the schema as follows.</p> <p><img src="https://www.aspsnippets.com/Handlers/DownloadFile.ashx?File=f18ac914-bc9b-437a-88e2-bd640ce05282.png" alt="" width="384" height="137" /></p> <p>I have already inserted few records in the table.</p> <p><img src="https://www.aspsnippets.com/Handlers/DownloadFile.ashx?File=b736972b-595c-4656-ab75-976e054877c7.png" alt="" width="340" height="156" /></p> <p>You can download the database table SQL by clicking the download link below.</p> <p><a href="https://www.aspsnippets.com/DownloadFile.aspx?File=Customers_Table_AutoIncrement.sql">Download SQL file</a></p> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <pre class="brush: csharp">using System.Configuration; using System.Data.SqlClient; using System.Data;</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() { string constr = ConfigurationManager.ConnectionStrings[&#34;Constring&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { string query = &#34;SELECT * FROM Customers&#34;; using (SqlCommand cmd = new SqlCommand(query)) { cmd.Connection = con; con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); return View(dt); } } } public ActionResult MenuLibroMayor(int? id) { // more code. return View(); } }</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;System.Data.DataTable&gt;&#34; %&gt; &lt;%@ Import Namespace=&#34;System.Data&#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;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#39;[id*=btnSend]&#39;).on(&#39;click&#39;, function () { var id = $(this).closest(&#39;tr&#39;).find(&#39;td&#39;).eq(0).html().trim(); $.post(&#34;/Home/MenuLibroMayor&#34;, { id: id }, function (r) { }); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;table class=&#34;table&#34;&gt; &lt;tr&gt; &lt;% foreach (DataColumn col in Model.Columns) { %&gt; &lt;th&gt;&lt;%: col.ColumnName%&gt;&lt;/th&gt; &lt;% } %&gt; &lt;th&gt;Action&lt;/th&gt; &lt;/tr&gt; &lt;% foreach (DataRow row in Model.Rows) { %&gt; &lt;tr&gt; &lt;% foreach (DataColumn col in Model.Columns) { %&gt; &lt;td&gt;&lt;%: row[col.ColumnName]%&gt;&lt;/td&gt; &lt;% } %&gt; &lt;td&gt;&lt;input type=&#34;submit&#34; value=&#34;Send&#34; id=&#34;btnSend&#34; /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% } %&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </pre> <p><strong><span style="text-decoration: underline;">Screenshots</span></strong></p> <p><strong>The Form</strong></p> <p><strong><img src="https://i.imgur.com/Srk8Fiz.jpg" alt="" width="396" height="248" /></strong></p> <p><strong>Id in Controller passed from View</strong></p> <p><strong><img src="https://i.imgur.com/TvYFUHq.jpg" alt="" width="419" height="86" /></strong></p>https://www.aspforums.net:443/Threads/622872/Pass-Table-Row-values-from-View-to-Controller-on-Button-Click-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/622872/Pass-Table-Row-values-from-View-to-Controller-on-Button-Click-in-ASPNet-MVC/Tue, 04 Dec 2018 01:54:57 GMT