Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试创建一个HtmlHelper来包装一个公共模式_C#_Asp.net Mvc - Fatal编程技术网

C# 尝试创建一个HtmlHelper来包装一个公共模式

C# 尝试创建一个HtmlHelper来包装一个公共模式,c#,asp.net-mvc,C#,Asp.net Mvc,我试图使用以下代码创建一个名为EditBlockFor的HTMLHelper方法,该方法接受模型并在一次过程中创建LabelFor和EditorFor,而不是每次都必须同时执行这两个操作。当需要从helper.labelf获取HtmlString时,我认为我正在正确地传递HtmlHelp,因为我没有可用的方法标签。我错过了什么 using System; using System.Collections.Generic; using System.Linq.Expressions; using

我试图使用以下代码创建一个名为EditBlockFor的HTMLHelper方法,该方法接受模型并在一次过程中创建LabelFor和EditorFor,而不是每次都必须同时执行这两个操作。当需要从helper.labelf获取HtmlString时,我认为我正在正确地传递HtmlHelp,因为我没有可用的方法标签。我错过了什么

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;

namespace MyTest.Code
{
    public static class HtmlHelperExtensions
    {
     public static IHtmlString EditBlockFor<T>
     (
     this HtmlHelper<T> helper,
     Expression<System.Func<T, String>> prop,
     Dictionary<String, Object> htmlAttributes = null
     )
        {
            HtmlString label;
            HtmlString item;


            label = helper.LabelFor(prop, htmlAttributes);
            item = helper.EditorFor(prop, htmlAttributes);

            return new HtmlString(label+" "+item);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq.Expressions;
使用System.Web;
使用System.Web.Mvc;
命名空间MyTest.Code
{
公共静态类HtmlHelperExtensions
{
公用静态IHtmlString EditBlockFor
(
这个HtmlHelper助手,
表情道具,
字典HtmlatAttributes=null
)
{
HtmlString标签;
HtmlString项目;
label=helper.LabelFor(prop,htmlAttributes);
item=helper.EditorFor(prop,htmlAttributes);
返回新的HtmlString(标签+“”+项);
}
}
}
忘记一个包含

使用System.Web.Mvc.Html