Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
¿Cómo paso tipos complejos a Html.LabelFor?

No funciona así, el error es:

Esperado ","

 @Html.LabelFor(ViewBag.OrganizationDetails => (string)ViewBag.OrganizationDetails.AddressLegal, htmlAttributes: new { @class = "control-label col-md-2" })

OrganizationDetails es una clase y AddressLegal es una cadena (necesita su valor)

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Prueba esto:

 @model ParentModel @Html.LabelFor(model => model.Name) @Html.LabelFor(model => model.Child.Name)

en tu caso debe ser:

 @model ViewBag.OrganizationDetails @Html.LabelFor(model => model.AddressLegal, new { @class = "control-label col-md-2" })

o

 @model ViewBag @Html.LabelFor(model => model.OrganizationDetails.AddressLegal, new { @class = "control-label col-md-2" })

no lo he probado

over 4 years ago · Santiago Trujillo Report

0

Tienes dos opciones.

La primera, al usar el ViewBag :

 @using Models @{ ViewBag.Title = "Home Page"; OrganizationDetails details = ViewBag.OrganizationDetails; } @Html.LabelFor(m => details.AddressLegal, htmlAttributes: new { @class = "control-label col-md-2" })

El segundo, use la versión fuertemente tipada de Html.LabelFor() pasando el modelo a la vista:

 public ActionResult Index() { var model = new OrganizationDetails() { AddressLegal = "Address" /* set another properties ... */}; return View(model); }

Y en la vista:

 @model Models.OrganizationDetails @Html.LabelFor(m => m.AddressLegal, htmlAttributes: new { @class = "control-label col-md-2" }) @Html.DisplayFor(m => m.AddressLegal)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!