c# - get HtmlHelper.textbox value as query string mvc -


i have following idea trying implement

@foreach (var item in model) { <div>user: @item.name<br />     scores: @item.scores<br />     @html.textbox("lastvisit");     @html.actionlink("update item", "updatemyitem", new  { name = item.name, lastvisit=?????  })     </div> } 

i have seen question pass text in query string, not want..

so question .. in above code how can replace (?????) value of textbox(lastvisit) , send value querysting in url of action link ??

notice opted not use webform own reason , know how webform.submit(), main concern how extract value of @htmlhelper.textbox()..

:)

something might help. work need render unique ids links , textboxes.

here example

action method simple model

public actionresult index(int? id) {     list<mymodel> mod = new list<mymodel>() {          new mymodel { selectedvalue = 1 } ,         new mymodel {selectedvalue = 2},         new mymodel {selectedvalue = 3}     };         return view(mod); } 

and view script.

@model list<mvc3stack.models.mymodel> @{     viewbag.title = "home page";     var = 1;     } <h2>@viewbag.message</h2> <script type="text/javascript">     $(document).ready(function () {         var lastvisits = $("input[id*='lastvisit']");         $(lastvisits).each(function () {             var = this.id.substring(this.id.length - 1);             var link = $("[id='testlink" + + "']");             if (link) {                 var _href = $(link).attr("href");                 $(link).attr("href", _href + "&lastvisit=" + $(this).val());             }         });     });  </script> @foreach (var item in model) {     @html.textbox("lastvisit" + i, item.selectedvalue )     @html.actionlink("testlink", "index", "home", new { id = "testlink" + });    <br />    i++; } <input type="button" value="getfile" id="getfile" /> 

here snapshot changed link

sample output

hope helps.

edit

my bad. here update javascript can trick.

$(document).ready(function () {     var lastvisits = $("input[id*='lastvisit']");      $(lastvisits).each(function () {         $(this).change(function () {             var = this.id.substring(this.id.length - 1);             var link = $("[id='testlink" + + "']");             if (link) {                 var _href = $(link).attr("href");                 $(link).attr("href", _href + "?lastvisit=" + $(this).val());             }         });     }); }); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -