asp.net mvc - using the same partial view with different buttons -


i have following partial view, lists users in table. each row has enroll button, enrolls user selected course.

i need same view task. however, need add users discussions (instead of enrolling them course). know can create view , change enroll buttons add buttons.

however, wonder if there more effective way of doing this. approach not seem easy maintain.

@model ienumerable<applicationuser> <h4>search results:</h4> <table class="table-condensed" style="font-size:smaller">     @foreach (var item in model)     {         <tr>             <td>                 @html.displayfor(modelitem => item.firstname)             </td>             <td>                 @html.displayfor(modelitem => item.lastname)             </td>             <td>                 @html.displayfor(modelitem => item.email)             </td>             <td>                 <input class="btn_enroll" data-userid="@item.id" value="enroll" type="button" />             </td>         </tr>     }  </table>  <script>     $(".btn_enroll").click(function () {         //code enrolling         var course_id = $("#hdn_selectedcourseid").val();     }) </script> 

one way setting attribute of calling action method render view

<table class="table-condensed" style="font-size:smaller" data-module="@viewdata["module"]"></table> 

and use in js code

<script> $(".btn_enroll").click(function () {     //code enrolling     var course_id = $("#hdn_selectedcourseid").val();     var moduletype = $(this).closest("table").attr("data-module");     if (moduletype === "enroll")     {         //do enrollment     }     else if (moduletype === "discussion")     {         //discuss here     }   }) 

for example on home page have links like

   @html.actionlink("enrollment", "index", new { module = "enroll" })    @html.actionlink("discussion", "index", new { module = "discussion" }) 

and applicationusercontroller has index action this

public actionresult index(string module) {     viewdata["module"] = module;      return view(); } 

however if scope of project or requirements can change enrollment and/or discussion better keep separate avoid complexity of code in single page in single js code.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -