Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6858683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:11:24+00:00 2026-05-27T02:11:24+00:00

I Have a View stronger Typed, of my class called Cliente , Defined like

  • 0

I Have a View stronger Typed, of my class called Cliente, Defined like this

public partial class Cliente
{
    public Cliente()
    {
        this.Campana = new HashSet<Campana>();
    }

    public short IdCliente { get; set; }
    public short IdDireccion { get; set; }
    public string Descripcion { get; set; }
    public bool Activo { get; set; }

    public virtual ICollection<Campana> Campana { get; set; }
    public virtual Direccion Direccion { get; set; }
}

I want to add The elements of the class Campana, so I passed into my viewBag like this

 ViewBag.Campanas = db.Campana;

Now what I want to know, it’s how can i Made a lambda expression to create labels, and fields based on the class. I tried like this but It doesn’t work

  @foreach (var item in ViewBag.Campanas)
  {
      @Html.LabelFor (modelItem => item.Descripcion)
  }

Here’s the Campana Class

public partial class Campana
{
    public Campana()
    {
        this.Servicio = new HashSet<Servicio>();
    }

    public short IdCampana { get; set; }
    public short IdCliente { get; set; }
    public string Descripcion { get; set; }
    public bool Activo { get; set; }

    public virtual Cliente Cliente { get; set; }
    public virtual ICollection<Servicio> Servicio { get; set; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:11:24+00:00Added an answer on May 27, 2026 at 2:11 am

    Now what I want to know, it’s how can i Made a lambda expression to
    create labels, and fields based on the class

    You can totally forget about lambdas and strong typing if you use this crap of ViewBag/ViewData. Not a chance. ViewBag is dynamic resolution that doesn’t provide any compile-time type safety.

    I would recommend you using view models and having your controller actions pass specific view model types to your views. Simply forget about the existence of ViewBag. It will make your code strongly typed and compile-time safe.

    There are so much articles and tutorials over the www teaching people this cancer of ViewBag. I am really sick of it. Please don’t ever use it in any of your applications.

    1. Define view models.
    2. Make your controller actions pass those view models to the views.
    3. Strongly type your views (@model MyViewModel)
    4. Use strongly typed helpers with lambda expressions and compile time safety in your views.

    Conclusion: it’s only once you have completely removed any trace of ViewBag/ViewData from your application we can talk about lambdas and strong typing in your views.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have view which looks something like this : <% using (Ajax.BeginForm(new AjaxOptions {
I have View Model with inner ViewModel Address propery. public class CommonViewModel{ public AddressViewModel
I have a strongly typed user control (partial) and I'd like to be able
In My Application i have View like this image: Now, I want to make
i have view like 'home/details/5', it can be access by anonymous user. but there
I have view stack in a app like so: <mx:ViewStack id=viewStack left=0 right=0 top=0
I have a view that is rendered with ContentType of application/msword. For users this
I have view for entering new entity. On that view I have two buttons:
Is this senerio valid? I have a View to maintain an Item. I have
I have view (frontend) in my own component (view.html.php): class MevViewMev extends JView{ function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.