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 9206749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:14:28+00:00 2026-06-18T00:14:28+00:00

Here i need to get the last value from a model list in a

  • 0

Here i need to get the last value from a model list in a view without looping it..Here is my controller code

public IList<ProductDetailModel> GetWPDetails()
            {
                ProductDetailModel Viewmodel;
                string funname = "GetCSpecialWPDetails";
                List<ProductDetailModel> getWPDetails = new List<ProductDetailModel>();
                getWPDetails = objrest.EcommerceWPDetails(funname);
                List<ProductDetailModel> WPDetails = new List<ProductDetailModel>();

                foreach (var item in getWPDetails)
                {
                    Viewmodel = new ProductDetailModel();
                    Viewmodel.Productid = item.Productid;
                    Viewmodel.ProductName = item.ProductName;
                    Viewmodel.CategoryID = item.CategoryID;
                    Viewmodel.ProductRate = item.ProductRate;
                    Viewmodel.DiscountRate = item.DiscountRate;
                    Viewmodel.imageurl1 = item.imageurl1;
                    WPDetails.Add(Viewmodel);
                }
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString);
                SqlCommand cmd = new SqlCommand("SELECT ThemeColor,LayoutDesign FROM dbo.Cpecial_Partner_Design WHERE [PartnerID]='" + Partid + "'", con);
                con.Open();

                using (SqlDataReader myReader = cmd.ExecuteReader())
                {
                    while (myReader.Read())
                    {
                        Viewmodel = new ProductDetailModel();
                        Viewmodel.ThemeColor = myReader["ThemeColor"].ToString();
                        Viewmodel.LayoutDesign = myReader["LayoutDesign"].ToString();
                        WPDetails.Add(Viewmodel);
                    }

                    myReader.Close();
                }
                con.Close();
                return WPDetails;

            }

and here in view i am getting the values by looping the model and the total count is 47 but what i need is i need the 47th value alone that is the last value alone without any looping.

View code

  @foreach (var item in Model)
       {
        @Html.EditorFor(modelItem => item.ThemeColor)
        @Html.EditorFor(modelItem => item.LayoutDesign)
       } 

Any suggestion?

  • 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-06-18T00:14:29+00:00Added an answer on June 18, 2026 at 12:14 am

    Use linq! In your case .Last() method.

    Try:

    @{ var last = Model.Last(); }
    @Html.EditorFor(modelItem => last.ThemeColor)
    @Html.EditorFor(modelItem => last.LayoutDesign)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get the value from a checkbox which is not hidden. Here
I need to get only the 2nd from last digit from the ui.value on
I'm stuck here: I need to get the values of org.jboss.system.server.ServerInfo With the code
I need a little help here: I get a file from an HTML upload
I would need little help here. I'm trying to get the git respository from
Here in this html i need to get the image name arrow_down using jquery
I need to only get tumblr posts which have been tagged with 'diary' Here
I either get a you need a ; here or a best overloaded match
I am using this simple code from here: https://developers.facebook.com/docs/mobile/android/build/#sig public class MainActivity extends Activity
trying to get last from the tag if data of last line is equal

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.