0

not experienced so bear with me.

I would like to use @Html.DisplayName (or something similar) for a value in database, it works fine with a foreach loop. But is there a way to show a value from database with the id of the row?

Sql DB Example

Lets say I have this db on sql and I only want to display CusName of ID 3 with @Html.DisplayName, is that possible orare there any alternatives to archieve this?

If possible please supply a working example, as I said im new so it is kinda confusing.

5
  • 1
    You need to filter data from database to achieve this. How are you retrieving database objects? Linq? Commented Jan 9, 2017 at 17:09
  • @Oscar yup, controller has using System.Linq; Commented Jan 9, 2017 at 17:15
  • db.table_name.Find(id) Commented Jan 9, 2017 at 17:42
  • Many LINQ examples here. Commented Jan 9, 2017 at 17:48
  • Please read How to Ask. Key phrases: "Search, and research" and "Explain ... any difficulties that have prevented you from solving it yourself". Commented Jan 9, 2017 at 18:16

1 Answer 1

1

You can use linq query in view page and filter the id using where clause or you could filter out the value in controller and pass it directly to view.

@foreach (var item in Model.Where(c => c.ID == 3))
        {
            //use your html display name here
        }
Sign up to request clarification or add additional context in comments.

Comments

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.