Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If it's an option, I'd suggest using unobtrusive AJAX to accomplish this. It takes a lot of the work and does it for you.</p> <p>So based on what you are attempting, you'd want to create a strongly typed Partial View that accepts a list of TableMeters as it's model class. (Forgive my lack of Razor, but I prefer C#...)</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;List&lt;TableMeters&gt;&gt;" %&gt; &lt;table&gt; &lt;% foreach(TableMeter meter in Model){ %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= meter.sno %&gt;&lt;/td&gt; &lt;td&gt;...&lt;/td&gt; &lt;/tr&gt; &lt;% } %&gt; </code></pre> <p>Then, on the main page, you'd want something along these lines:</p> <pre><code>&lt;% using(Ajax.BeginForm("MeterInfo", "Power", new AjaxOptions() { UpdateTargetId = "meterTable" })){ %&gt; &lt;%= Html.DropDownList("meter_id", new SelectList(Model, "sno", "meter_name"), "-- Select Meter --", new { id = "meters", onchange="$(this).parent().submit()" }) %&gt; &lt;% } %&gt; &lt;div id="meterTable"&gt; &lt;%= Html.Partial("MeterTable", Model.TblMeters) %&gt; &lt;/div&gt; </code></pre> <p>Your controller method can stay mostly the same, but you'll need drop the [HttpGet] and change the return to:</p> <pre><code>return PartialView("MeterTable", _meter); </code></pre> <p>Double check the logic as far as what is getting passed around, I'm not entirely sure what all of your classes look like, but that should do the trick. When you change the dropdown, it will trigger the "onchange" event, which should submit the containing form. The form will submit via AJAX to the controller. Note that the name of the dropdown must match the parameter for the controller method. You can do your filtering like you already have it, and return the list to the partial view. The partial view will populate, and replace the contents of the div.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      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