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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:13:57+00:00 2026-05-26T17:13:57+00:00

Okay, I’m working on a problem that I’ve been holding off on for three

  • 0

Okay, I’m working on a problem that I’ve been holding off on for three months. I have created a View that iterates through all of my ViewModels that implement IStepViewModel. I need to display a form title on the view that indicates in plain english the current step the user is working on. I would like to do this with DataAnnotations, so I just have to decorate each ViewModel like so [StepTitle("Ownership Information")]. I’ve tried to do this but I couldn’t get it to work. Meaning, that my ModelDataProvider would get called, it would not load the information into metadata.AdditionalValues and when my view gets loaded and I would try to read ViewData.ModelMetadata.AdditionalValues["WizardStep"] it did not exist.

I’ll include my custom provider and Attribute classes at the bottom.

Index.cshtml

@using Microsoft.Web.Mvc;
@using Tangible.Models;

@model Tangible.Models.WizardViewModel 

@{ 
    var currentStep = Model.Steps[Model.CurrentStepIndex];
    var progress = ((Double)(Model.CurrentStepIndex) / Model.Steps.Count) * 100;
} 
<script type="text/javascript">
    $(function () {
        $("#progressbar").progressbar({
            value: @progress
        });
    });

</script> 

    @Html.ValidationSummary()
@using (Html.BeginForm())
{ 
<div id="progressbar" style="height:20px;">
<span style="position:absolute;line-height:1.2em; margin-left:10px;">Step @(Model.CurrentStepIndex + 1) out of @Model.Steps.Count</span> 
</div>
<br /> 

    if (Model.CurrentStepIndex > 0)
    { 
        <input type="submit" value="Previous" name="prev" /> 
    }

    if (Model.CurrentStepIndex < Model.Steps.Count - 1)
    { 
        <input type="submit" value="Save &amp; Continue" name="next"  /> 
    }
    else
    { 
        <input type="submit" value="Finish" name="finish" /> 
    }

         @*<input type="submit" value="Save" name="Save" />*@    



    @Html.Serialize("wizard", Model) 

    @Html.Hidden("StepType", Model.Steps[Model.CurrentStepIndex].GetType()) 


    @Html.EditorFor(x => currentStep, null, "") 

    if (Model.CurrentStepIndex > 0)
    { 
        <input type="submit" value="Previous" name="prev" /> 
    }

    if (Model.CurrentStepIndex < Model.Steps.Count - 1)
    { 
        <input type="submit" value="Save &amp; Continue" name="next"  /> 
    }
    else
    { 
        <input type="submit" value="Finish" name="finish" /> 
    }

         @*<input type="submit" value="Save" name="Save" />*@  


}

CustomAttribute

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Web.Mvc;


namespace Tangible.Attributes
{

    public enum HtmlTextLengthAttribute 
    {
        Description=50,
        Long = 35,
        Default = 60,
        Short = 10,
        Email = 30
    }

    public interface ICustomModelMetaDataAttribute
    {

    }



    [AttributeUsage(AttributeTargets.Class, AllowMultiple= false, Inherited = true)]
    public sealed class WizardStepAttribute : Attribute, ICustomModelMetaDataAttribute
    {
        public WizardStepAttribute() : base() { }

        public String Name { get; set; }
        //public virtual int? Order { get; set; }

        public IDictionary<string, object> WizardStepAttributes()
        {
            IDictionary<string, object> attribs = new Dictionary<string, object>();

            //attribs = this.GetType().GetProperties().ToDictionary(p => p.Name, p=> p.GetValue(this,null)) ; 
            attribs.Add("Name", Name);

            return attribs;
        }

    }

    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public class HtmlPropertiesAttribute : Attribute, ICustomModelMetaDataAttribute
    {
        public HtmlPropertiesAttribute()
        {
            Size = (int) HtmlTextLengthAttribute.Default;
        }
        public string CssClass
        {
            get;
            set;
        }

        /// <summary>
        /// Enter the actual number of characters you want to display in the field.
        /// </summary>
        public int Size
        {
            get;
            set;
        }
        public IDictionary<string, object> HtmlAttributes()
        {
            //Todo: we could use TypeDescriptor to get the dictionary of properties and their values
            IDictionary<string, object> htmlatts = new Dictionary<string, object>();
            if (Size != 0)
            {
                htmlatts.Add("size", Size);
            }
            return htmlatts;
        }
    }



}

Custom ModelMetaDataProvider

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tangible.Attributes;

namespace Tangible.Providers
{

    public class ModelMetadataProvider : DataAnnotationsModelMetadataProvider
    {

        protected override ModelMetadata CreateMetadata(IEnumerable<System.Attribute> attributes, System.Type containerType, System.Func<object> modelAccessor, System.Type modelType, string propertyName)
        {
            var metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
            var customAttr = attributes.OfType<ICustomModelMetaDataAttribute>();
            if (customAttr != null)
            {
                foreach (var itr in customAttr)
                {
                    metadata.AdditionalValues.Add(itr.GetType().Name, itr);
                }


            }
            return metadata;
        }


    }

    }
  • 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-26T17:13:58+00:00Added an answer on May 26, 2026 at 5:13 pm

    I had to hard code my my view. It was my only option.

       @switch (Model.CurrentStepIndex)
        case 0: 
             <h2>Preparer's Information</h2>
            break;
        case 1:
        <h2>Owner's Information</h2>
            break;
        case 2:
        <h2>Physical Location</h2>
            break;
        case 3:
        <h2>About this business</h2>
            break;
        case 4:
        <h2>Describe Business</h2>
            break;
        case 6:
            <h2>Sale or Change of Ownership</h2>
            break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, here's the scenario. I have a utility that processes tons of records, and
Okay I have created an application where in one of the screens I have
Okay, I have hundreds of .net controls with text attributes that needs to be
Okay so what I have is a table that keeps track of history on
Okay i have this problem with every page i make. im not sure what
Okay, so I have been developing in Java for a little over a year
Okay so im working on this php image upload system but for some reason
Okay, we know that the following two lines are equivalent - (0 == i)
Okay, none of the previous questions I have seen with this error seem to
Okay so my question is this. Say I have a simple C++ code: #include

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.