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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:12:54+00:00 2026-06-13T23:12:54+00:00

I am re-opening my question as it has been set as duplicate while it

  • 0

I am re-opening my question as it has been set as duplicate while it is not – or people who tagged it as duplicate should explain me why it is a duplicate……….
https://stackoverflow.com/questions/13227988/html-displayfor-result

How can I get the result of the method Html.DisplayFor() in a C# Class, like in a View model or even in a Controller ? And not in the View Aspx or Razor.

[Edit]
In fact I have a table to display and depending on the number of record I use a Telerik table or a simple HTLM table.

For the moment I have a function in my view to get the string to display for each column so I use the same format for both tables.

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ViewModels.OrderViewModel>" %>

<script runat="server" type="text/C#">

public string GetCellValue (String columnName, Order order)
{
        string value = "";
        switch (columnName)
        {
            case "Ref":
                value = order.order.Reference.ToString(); break;
            case "Etc":
                value = Html.DisplayFor(p => order.order.Etc).ToHtmlString();break;             
            case "Payment date": 
                foreach (Executions ex in order.executions)
                {
                    value += ex.Date.Date.ToString("yyyy-MM-dd") + " ";
                }
                break;      

I want to move this function out of my view in the ViewModel for example, but I do not know how I can call the function Html.DisplayFor() out of a view.

  • 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-13T23:12:55+00:00Added an answer on June 13, 2026 at 11:12 pm

    Don’t understand why would you want to do it, but…

    using System.Web.Mvc;
    using System.Web.Mvc.Html;
    
    class Example {    
    
        void Method()
        {
           HtmlHelper<TModel> Html = new HtmlHelper<TModel>();
           MvcHtmlString result = Html.DisplayFor(prop => Model.Prop);
        }
    }
    

    After your edit, if you move GetCellValue to another place, maybe you will only need to do

           MvcHtmlString result = new MvcHtmlString(order.order.Etc);
    

    as, it should only display its value as string (unless you have set up a template for it).

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

Sidebar

Related Questions

I know the question of how to pass parameters has been asked a while
I have a question regarding php and opening files PHP has more than one
What's up people. Something's been bothering me for a while now... and I was
I know this question has been asked many times before but I can't find
Triggered by another question (which has been subsequently edited away though), I wanted to
I'm new to this forum, and I have a question that has been bothering
I am sure this question has been asked and answered; but I haven't managed
I'm sorry for opening a new question, I had to - as I wrote
Simple question: I am opening a file in matlab 7.x, and I want to
Just a quick question.. Following opening a text file in a separate definition (no

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.