Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC jQuery
hello,
I used the following code and I want get value of hdn1(hidden field)
var grid = new WebGrid(Model, rowsPerPage: 15, ajaxUpdateContainerId: "myGrid");
  @grid.GetHtml(tableStyle: "clrPreview", columns: grid.Columns(
  grid.Column("CityName", "City", canSort:false),
                                              grid.Column("HotelName", "Hotel", canSort: false),
                                              grid.Column("HotelCategoryName", "Category", canSort: false),
                                              grid.Column("GitRangeStartFrom", "Git Range Start From", canSort: false),
                                       grid.Column(columnName: "Action", canSort: false,
                                          format: @<text><input type="hidden" id="hdn1" value='@item.HotelId'  />
  @Html.ActionLink("Edit", "Edit", new { id = item.HotelId }, new { rowid = item.HotelId })
  @* |  @Html.ActionLink("Delete", "Delete", new { id = item.HotelId })*@
  </text>)
I want to get hidden field value by jquery
Posted 1-May-13 1:01am
Edited 1-May-13 1:33am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Your problem is that you can not have multiple elements with the same ID. But with the pattern you use for that column you will generate inputs with the same ID. That won't work, since besides the fact that you violate the html standard, jquery can not grab it.
You have could use more approaches:
- just add a class to that input element, and no ID. And if you have already the row, you can grab it's child with that class - and that will be the input you want. Or if you have any other element in that row you can use the jquery dom navigation tools to get that. If it is the only hidden element input in the row you will probably don't need even the class.
- use the id from the model (@item.HotelId) to generate ID
If you need the id on the other columns of the row (and forget the hidden input):
- use the Style property of WebGridColumn to add a special class that holds the model id
- use the Format property as you used but add id as custom html property to the element you generate
 
All these can be used, an probably more, but you have to choose based on what you want to do with that value.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

var hv = $('#hdn1').val();
 
Should do the trick.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100