0

嗨,我的代码中有这样的内容:`

 <div>Room:@Html.TextBox("RoomID")</div>  
<div>Nume:@Html.TextBox("FirstName")</div>
<div>Prenume:@Html.TextBox("LastName")</div>
<div>Telefon:@Html.TextBox("Phone")</div>
 <div>Data Nasterii:@Html.TextBox("Birthday")</div>
<h3>Address</h3>
<div>Tara:@Html.TextBox("Tara")</div>
<div>Oras:@Html.TextBox("Oras")</div>
<div>Judet:@Html.TextBox("Judet")</div>
<div>Strada:@Html.TextBox("Strada")</div>
<div>tipclient:@Html.TextBox("GuestTypeId")</div> 
<div>Data In:@Html.TextBox("Data_Check_in")</div>
<div>Data OUT:@Html.TextBox("Data_Check_out")</div>  `

我怎样才能使它 <div>Room:@Html.TextBox("RoomID")</div>对客户端不可见或如何使它只读?

4

1 回答 1

4

You could use a hidden field:

@Html.Hidden("RoomID")

or if you want to make it visible to the client but readonly:

@Html.TextBox("RoomID", Model.RoomID, new { @readonly = "readonly" })

or using the strongly typed versions which obviously are preferred:

@Html.HiddenFor(x => x.RoomID)

or:

@Html.TextBox(x => x.RoomID, new { @readonly = "readonly" })

or if you want to use a hidden field yet another possibility is to decorate your view model property with the [HiddenInput] attribute:

[HiddenInput(DisplayValue = false)]
public int RoomID { get; set; }

and in your view simply use an editor template:

@Html.EditorFor(x => x.RoomID)

But no matter what you do or choose please use view models and strongly typed versions of those helpers.

于 2012-05-14T20:45:26.993 回答