1

How to dynamically bind data to label in Asp.net MVC. I have table where i need to display all compnay name dayanamically. I did create a Model for compnay name.

code in model look like this,

public class CompnayName
 {
     public string compnayName { get; set; }
     public string address { get; set; }

 }
2
  • what are you using as data source? Commented Feb 4, 2011 at 14:54
  • I am using SQL as data source. Commented Feb 4, 2011 at 15:11

1 Answer 1

1

Please first correct spelling of the class name ;-)

Your asp page needs to inherit from your model:

Inherits="System.Web.Mvc.ViewPage<namespace.CompanyName>"

Then uses LabeFor:

<%= Html.LabelFor(m => Model.companyName)%>

That should do the trick.

Sign up to request clarification or add additional context in comments.

2 Comments

Inherits="System.Web.Mvc.ViewPage<namespace.CompanyName>"
you gotta understand, it's not a company, it's a comp-Nay, dog!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.