Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I run over Items collection and want to build TextBox but I get the following error:
'System.Web.Mvc.HtmlHelper<Web.Module>' does not contain a definition for 'TextBoxFor' and the best extension method overload 'System.Web.Mvc.Html.InputExtenstions.TextBoxFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>,System.Linq.Expressions.Expression<System.Func<TModel, TProperty>>)' has some invalid arguments
I think my anonymous function is wrong, but why?
Please help me

SocialNetworkModel class
    public class SocialNetworkModel : IViewModel
    {
        #region Properties
        public List<SocialNetworkItem> Items { get; set; }
        #endregion
        #region Methods
        public SocialNetworkModel(string param)
        {
            this.Create(param);
        }
        /// <summary>
        /// DO NOT DELETE: default .ctor is used when binding posted data, from client, back to the model 
        /// </summary>
        public SocialNetworkModel() { }
        public void Create(string param)
        {
            Items = new List<SocialNetworkItem>();
            foreach(var item in Customer.Current.GetSocialNetworkList())
            {
                Items.Add(new SocialNetworkItem
                {
                    CodeName = item.CodeName,
                    Link = item.Link,
                    UserName = item.UserName,
                    Password = item.Password
                });
            }
        }
        #endregion
    }
public class SocialNetworkItem
    {
        #region Properties
        [LocalizedDisplayName("CodeName", NameResourceType = typeof(Resources.Views.SocialNetwork))]
        public string CodeName { get; set; }
        [LocalizedDisplayName("Link", NameResourceType = typeof(Resources.Views.SocialNetwork))]
        public string Link { get; set; }
        [LocalizedDisplayName("UserName", NameResourceType = typeof(Resources.Views.SocialNetwork))]
        public string UserName { get; set; }
        [LocalizedDisplayName("Password", NameResourceType = typeof(Resources.Views.SocialNetwork))]
        public string Password { get; set; }
        #endregion
    }


ViewUserControl
XML
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Module>" %>
<% var model = Model.Model as SocialNetworkModel; %>
<div id="social-network-container">
    <div id="social-network">
        <% using (Ajax.BeginForm(Model.CodeName + "FormPost", "Customer", null, new AjaxOptions() { HttpMethod = "POST" }, new { @class = "form-container" }))
           { %>
                <%model.Items.ForEach(item => { %>                
                    <%: Html.TextBoxFor<SocialNetworkItem, string>(s => item.Link)%>
                <%}); %>
           <% }%>
    </div>
</div>




dsf
df
Posted

1 solution

Try this

XML
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Module>" %>
<% var model = Model.Model as SocialNetworkModel; %>
<div id="social-network-container">
    <div id="social-network">
        <% using (Ajax.BeginForm(Model.CodeName + "FormPost", "Customer", null, new AjaxOptions() { HttpMethod = "POST" }, new { @class = "form-container" }))
           { 
                model.Items.ForEach((item) => {
                    Html.TextBoxFor<SocialNetworkItem, string>(s => item.Link)
                }); 
           }%>
    </div>
</div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900