javascript - MVC 4 button onClick that is calling razor function -


i have mvc 4 application. here case:
1. model hashkey - containing 1 string key
2. model modelobjecta - object transport.
3. class - generate unique key on request , put in tempdata along given modelobjecta , returns unique key.
4. controller controllermodelobjecta - serve as pure controller.
5. view showallmodelobjecta - view page display collection controller.

how works. have request navigate showallmodelobjecta. controller call class object transfer , sends unique key showallmodelobjecta. view calls method (not httpget) object coresponding received key controller. collection of object received , in @foreach loop disassembles objects , put them in table. along object in table putted 3 buttons represents different functions (view details, edit, delete) corresponding object.

the problem: on each object`s button have use @functions call classa , send object itself, on click not on loop.

here code (i have change names :) )

@functions{     public string buttonclicked(modelobjecta object)     {         system.diagnostics.debug.writeline("in");// check when method called         return "dae";     } }  foreach loop:   <table>             @foreach (modelobjecta  object in modelobjectacollection)             {             <tr>                 <td>                     @html.displayfor(modelitem => object.name)                 </td>                 <td>                     @html.displayfor(modelitem => object.email)                 </td>                 <td>                     <button type="button" id="details" value="@object" onclick="hello(value);">details</button>                     <button type="button" value="@object">edit</button>                     <button type="button" value="@object">delete</button>                 </td>             </tr>             }     </table>  <script type="text/javascript">     function hello(value) {       alert("clicked");     }  </script> 

since have access @modelobjecta cant send razor function, because java on client side , razor on server.

is there way make this?

edit: here rentered buttons:

 <td>                      <button type="button" id="details" value="(project path).modelobjecta" onclick="hello(value);">details</button>                     <button type="button" value="(project path).modelobjecta">edit</button>                     <button type="button" value="(project path).modelobjecta">delete</button>                 </td> 

edit 2: not sure need use fulfill requirement. open suggestions.

by code pasted problem putting class name in value tag. try this:

@foreach (modelobjecta mobja in modeldealercollection) {     <tr>         <td>             @html.displayfor(modelitem => modelobjecta.name)         </td>         <td>             @html.displayfor(modelitem => modelobjecta.email)         </td>         <td>             <button type="button" id="details" value="@mobja" onclick="hello(value);">details</button>             <button type="button" value="@mobja">edit</button>             <button type="button" value="@mobja">delete</button>         </td>     </tr> } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -