Click here to Skip to main content
13,044,705 members (51,978 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 })*@

I want to get hidden field value by jquery
Posted 1-May-13 0:01am
Updated 1-May-13 0:33am
Rate this: bad
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

var hv = $('#hdn1').val();

Should do the trick.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2017
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