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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:41:40+00:00 2026-06-08T12:41:40+00:00

I have a unique ‘string’ does not contain definition problem. Take following VIew code:

  • 0

I have a unique ‘string’ does not contain definition problem.

Take following VIew code:

@if (ViewBag.Stories != null)
{
    if (ViewBag.Stories.Count > 0)
    {
    <h2>Stories (@ViewBag.Stories.Count)</h2>
    <ul>
        @foreach (var item in ViewBag.Stories)
        {
            <li>
                @("test".ToString().ToSeoUrl())
                <h2>@(item.Title.ToString().ToSeoUrl())</h2>
            </li>
        }
    </ul>
    }
}

If I remove ‘.ToString().ToSeoUrl()’ from item.Title I get:

  • test

    title

  • test

    title

  • test

    title

If I add it back. I get the excepction

Server Error in ‘/’ Application.

‘string’ does not contain a definition for ‘ToSeoUrl’

I’m using Razor and have the following helper class registered in the View:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web.Mvc;

namespace MyNamespace.Helpers
{    
    public static class StringExtensions
    {
        public static string ToSeoUrl(this string url)
        {
        // make the url lowercase
        string encodedUrl = (url ?? "").ToLower();

        // replace & with and
        encodedUrl = Regex.Replace(encodedUrl, @"\&+", "and");

        // remove characters
        encodedUrl = encodedUrl.Replace("'", "");

        // remove invalid characters
        encodedUrl = Regex.Replace(encodedUrl, @"[^a-z0-9]", "-");

        // remove duplicates
        encodedUrl = Regex.Replace(encodedUrl, @"-+", "-");

        // trim leading & trailing characters
        encodedUrl = encodedUrl.Trim('-');

        return encodedUrl;
        }
    }
}

item is a custom class called Story with a public string Title

  • 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-08T12:41:42+00:00Added an answer on June 8, 2026 at 12:41 pm

    Extension methods cannot be dynamically dispatched. Because you are using ViewBag which is dynamic and ToSeoUrl which is an extension method you get an RuntimeBinderException.

    There are two ways to solve this:

    1. Use casting: <h2>@(((string)item.Title).ToSeoUrl())</h2> calling ToString() is not enough because it will be also dynamically dispatched.
    2. Call your extension method without the extension method syntax as a normal static method: <h2>@(StringExtensions.ToSeoUrl(item.Title))</h2>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem is the following. There are multiple rows that have non-unique identifiers: id
I know that using the following codes will make each column have unique values,
I have a unique industrial application where I do not want the Windows CE
How can I have a HashMap with unique keys in Java? Or even does
Why does INDEX creation statement have UNIQUE argument? As I understand, the non-clustered index
I want the innerHTML of some spans that do not have a unique ID
I have the following code to get the get the relationship between the tables
Because Microsoft did not include a way to have unique constraints in sharepoint, this
How can I break this string for licence plates v/s states? I have unique
All Hadoop jobs have unique jobid. You can use jobid to get job status

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.