27313

How do I pass the string value parameter of the selected list item from an auto-populated dropdown l

I have created an auto-populated drop downlist on my MVC 4 web application. When the user selects an item from the dropdown list, I want the partial view to show the item selected rather than all items as it already displays in this partial view. How do I pass the string value parameter of the selected list item from an auto-populated dropdown list to a partial view controller? Here is the code for my auto populated dropdown list:

@foreach (var m in ViewDatamodel) { if (m.State == "In Work") { <li><a href="@Html.RenderAction("_GetforStatus", "Status" /@* I am assuming that I need to place the TargetName here, but not too sure exactly how *@)">@m.TargetName</a></li> } }

I want to pass the m.TargetName string as a parameter so that i can manuipulate the partialview based on which list item is selected. The partialview consists of progress bars for jobs being performed where the data is stored on a SQL Server DB. I use the following Ajax Script to refresh the original partial view every 3 seconds. I need to be able to do the same with the selectedd partial views. Again, this is all autopopulated, so I am assuming the best way is to go by the TargetName:

<script> function loadpartialView() { $.ajax({ url: '@Url.Action("_GetfoeStatus', "Status")', type: 'POST', data: '{}', //I am assuming that I will need to pass the parameter to here cache: 'false', async: 'true', success: function (result) { $('#progress').html(result); } }); } $(function() //..... Refresh Timer

Answer1:

Both the Action and RenderAction methods have overloads that allow you to pass additional parameters that are appended to the query string for the resource.

If you are doing this on the server side, you can:

Html.RenderAction("_GetForStatus", "Status", new { TargetName = m.TargetName })

If you are doing this on the client side, you would have to write some additional jQuery to make it work (or just plain old Javascript).

function loadpartialView() { $.ajax({ url: '@Url.Action("_GetfoeStatus', "Status")', type: 'POST', data: { TargetName: $("#YourDropDown").val() } cache: 'false', async: 'true', success: function (result) { $('#progress').html(result); }}); }

I used "TargetName" because I didn't know what your parameter name is.

Recommend

  • Should I start on ASP.NET MVC 1 or MVC 2 Beta?
  • How to see every controller & action method called in ASP.Net MVC?
  • How to pass the id of the parent to the create view of a child
  • HTML ordered list indent to keep original numbering
  • jQuery e.stopPropagation() - how to use without breaking dropbox functionality altogether?
  • Dropdown menu items hides behind main menu in bootstrap customized navigation bar
  • keydown event triggered only once
  • ember js subviews and didinsertelement event
  • How to activate JS data-filter when page loads?
  • jQuery-Marquee only working in Firefox
  • acts_as_taggable_on Tags added twice
  • Touch events over two dom elements?
  • JQuery Add class to certain list item
  • Jquery Show & ScrollTop (or ScrollTo)
  • Function JavaScript : on Menu CSS HTML
  • Can't delete li from to-do list
  • Cut the background to expose the layer below
  • How Get arguments value using inline assembly in C without Glibc?
  • SQL Query - Table Joining Problems
  • Can't remove headers after they are sent
  • How to make R's read_csv2() recognise the text characters properly
  • Angularjs pass function from Controller to Directive (or call controller function from directive) -
  • Simulate click Geckofx vb,net
  • Implementation of State Monad
  • How to use JavaScript to determine whether a file exists in a directory?
  • Jquery UI tool tip close icon
  • Using jQuery closest() method with class selector
  • HTML download movie download link
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • Jquery - Jquery Wysiwyg return html as a string
  • How to get icons for entities from eclipse?
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • Authorize attributes not working in MVC 4
  • EntityFramework adding new object to nested object collection
  • JaxB to read class hierarchy
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?