Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your code a has a number of wrong points. I am suggesting an alternative approach using ajax</p> <p>1.Using the foreach you are making a number of forms within a single page. and while submitting you are submitting the first form(<code>document.forms[0].submit()</code>). alone</p> <p>rewrite Your html as follows</p> <pre><code>@foreach (var product in Model) { &lt;tr&gt; &lt;td&gt; &lt;a href="#" id="submit_form" onclick="submitForm(@product.Id);"&gt;&lt;/a&gt; &lt;/td&gt; &lt;td&gt; @product.Name &lt;/td&gt; &lt;/tr&gt; } </code></pre> <p>and make ajax call to the server using jquery.</p> <pre><code>var productid; function submitForm(productid) { $.ajax({ type: 'GET', url: "/Home/SelectProduct?productId="+productid, contentType: "application/json; charset=utf-8", success: function (_results) { $("#resultdiv").html(_results); }, error: function (_results) { } }); } </code></pre> <p>and accept the productid as a query string</p> <pre><code>var ProductId=HttpContext.Request.QueryString["productId"] </code></pre> <p>2.Still if you are following the same approach... You are expecting the query string as a parameter in the action method. Its wrong</p> <p>You can accept it like this. (In the following snippet <code>using (Html.BeginForm("SelectProduct", "Home", new {productId = product.Id}))</code> the productId property u have added can be accepted as a query string in the server side method.)</p> <pre><code>var ProductId=HttpContext.Request.QueryString["productId"] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload