पर एक कस्टम एचटीएमएल हेल्पर जोड़ना मैं एक अच्छा उदाहरण/ट्यूटोरियल खोजने का प्रयास कर रहा हूं, यह बताते हुए कि मैं अपने एमवीसी 3 रेजर एप्लिकेशन के लिए अपने स्वयं के कस्टम एचटीएमएल हेल्पर्स कैसे बना सकता हूं और इसका उपयोग कर रहा हूं, मुझे यह पता चला है के रूप मेंएमवीसी प्रोजेक्ट
Adding your own HtmlHelper in ASP.NET MVC 3
इस प्रकार मैं, इसलिए
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace MyWebApp
{
public static class ExtensionMethods
{
public static MvcHtmlString StateDropDownListFor<TModel, TValue>
(this HtmlHelper<TModel> html,
Expression<Func<TModel, TValue>> expression)
{
Dictionary<string, string> stateList = new Dictionary<string, string>()
{
{"AL"," Alabama"},
{"AK"," Alaska"},
{"AZ"," Arizona"},
{"AR"," Arkansas"}
};
return html.DropDownListFor(expression,
new SelectList(stateList, "key", "value"));
}
}
}
अब तक तो अच्छा के रूप में एक वर्ग (एक सा यह कांट छांट) बना लिया है
मेरी नियंत्रक के अंदर मैं भी संदर्भ
using System.Web.Mvc.Html;
अब मेरे विचार अंदर मैं निम्नलिखित है
@Html.StateDropDownList(x => x.State)
लेकिन मैं निम्न त्रुटि
System.web.mvc.htmlhelper<system.collections.generic.list<Profile.ProfileImages>> does not contain a definition for StateDropDownList and no extension method StateDropDownList acception a first argument of type system.web.mvc.htmlhelper<System.Collections.Generic.List<Profile.ProfileImages>> could be found(Are you missing a using directive of an assembly reference?)
सका कोई मुझे बता पाने जोड़ा क्या मैं यहाँ गलत कर रहा हूँ।
क्या आपके पास DisplayImageFor नामक एक HTML सहायक है? –
@ UfukHacıoğulları क्षमा करें मैंने गलत त्रुटि कथन जोड़ा है, मैंने उपरोक्त अद्यतन किया है। –