2

I have a model:

public class SomethingViewModel 
{
    [Required]
    [Display(Name = "Customer")]
    public string SomethingName { get; set; }

    [Required]
    [Display(Name = "Something id")]
    public string SomethingId { get; set; }

}

I need to create a view for Html.EditorForModel but I need field SomethingName only display(label). How to do this?

UPDATE: I need use attributes

Fred
  • 3,365
  • 4
  • 36
  • 57
Mediator
  • 14,951
  • 35
  • 113
  • 191

1 Answers1

0

You'd have to individually setup your LabelFors and EditorFors. Try something like:

@Html.LabelFor(m => m.SomethingName)
@Html.EditorFor(m => m.SomethingName)

@Html.LabelFor(m => m.SomethingId)
@Html.EditorFor(m => m.SomethingId)

Or for just displaying:

@Html.LabelFor(m => m.SomethingName)
@Html.DisplayFor(m => m.SomethingName)

@Html.LabelFor(m => m.SomethingId)
@Html.DisplayFor(m => m.SomethingId)
Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
  • I update my post. I need work with Html.EditorForModel and atributtes – Mediator Mar 12 '13 at 13:12
  • @simplydenis The above works for attributes, but `EditorForModel` doesn't actually display the labels, that's why you'll have to do that yourself. Otherwise you'd have to create your own editor template for your model. – Mathew Thompson Mar 12 '13 at 15:21