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

  • Home
  • SEARCH
  • 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 6832713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:53:31+00:00 2026-05-26T22:53:31+00:00

ASP.net mvc in new for me, for some time I used php (no mvc),

  • 0

ASP.net mvc in new for me, for some time I used php (no mvc), but now i’m interested, how I can fetch one row from db? without foreach, for example in title…

here is some code:
controller

 public ActionResult Index()
        {
            var pages = (from page in db.Pages where page.PageName == "index" select page).ToList();
            return View(pages);
        }

view:

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <% foreach (var item in Model)
       { %>
    <%= Html.Encode(item.Text) %>
    <% }
    %>
</asp:Content>
  • 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-26T22:53:32+00:00Added an answer on May 26, 2026 at 10:53 pm

    In your controller, instead of .ToList() you can use the .FirstOrDefault() method, this will return only the first row from the database.

    Then in your view you won’t need the foreach.

    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
        <%= Html.Encode(item.Model.Text) %>
    </asp:Content>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to ASP.net MVC architecture. I have read in some articles that
I'm really new to ASP.NET MVC, and I'm trying to integrate some Javascript into
I'd like to have some of the ScriptManager features in the new Asp.net MVC
All, I'm starting a new ASP.NET MVC project which requires some content management capabilities.
I am taking some time to learn how to develop asp.net mvc2 websites, but
I have built an ASP.NET MVC app some time ago, and after a few
I am semi-new to ASP.NET MVC. I am building an app that is used
I am uploading files using HttpWebRequest to an ASP.Net MVC application but, for some
First, some background: I'm new to ASP.NET MVC 2 and NHibernate. I'm starting my
I'm planning to design simple website using ASP.NET MVC new technology. Many concepts are

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.