Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.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# ASP MVC:创建表达式<;Func<;TModel,TValue>&燃气轮机;编程表达_C#_Asp.net Mvc - Fatal编程技术网

C# ASP MVC:创建表达式<;Func<;TModel,TValue>&燃气轮机;编程表达

C# ASP MVC:创建表达式<;Func<;TModel,TValue>&燃气轮机;编程表达,c#,asp.net-mvc,C#,Asp.net Mvc,我想用这个函数生成一个MVC编辑器 System.Web.Mvc.Html.EditorExtensions.EditorFor<TModel, TValue>( this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, object htmlAttributes = null) System.Web.Mvc.Html.Edi

我想用这个函数生成一个MVC编辑器

System.Web.Mvc.Html.EditorExtensions.EditorFor<TModel, TValue>(
       this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, 
       object htmlAttributes = null)
System.Web.Mvc.Html.EditorExtensions.EditorFor(
这个HtmlHelper html,表达式,
对象htmlAttributes=null)
问题在于

Expression<Func<TModel, TValue>> expression
表达式
因为我只有财产的名称。我确信该属性存在,并且我可以得到模型的实际实例

如何创建正确的参数

编辑:要使其更清晰,请执行以下操作: 我有模型,我有属性的名称,我想创建表达式>

谢谢


Peter

如果将属性名称作为字符串,请使用扩展名方法,而不是
EditorFor

e、 g


约翰纳森·巴克利的回答指引着我正确的道路

我现在使用html.Editor而不是html.Editor

这里是对generator类代码的提取:

 public static MvcHtmlString GenerateStepTwo(this HtmlHelper<InputModell> html, InputModell modell)
    {
     ...
     foreach (var actField in fieldsSorted)
        {
        ...
        editor = html.Editor(fieldname, new { htmlAttributes = new { @class = "form-control", style = "max-width:200px;min-width:100px" } });

        all.AppendLine(AddOpenImageFunc(editor, fieldname));
...
}
return all;
public static MvcHtmlString GenerateStepTwo(此HtmlHelper html,InputModell modell)
{
...
foreach(FieldsOrted中的var actField)
{
...
editor=html.editor(fieldname,new{htmlAttributes=new{@class=“form control”,style=“最大宽度:200px;最小宽度:100px”});
AppendLine(AddOpenImageFunc(编辑器,字段名));
...
}
全部归还;
谢谢!
Peter

您是否尝试过
Html.EditorFor(model=>model.SomeProperty);
 public static MvcHtmlString GenerateStepTwo(this HtmlHelper<InputModell> html, InputModell modell)
    {
     ...
     foreach (var actField in fieldsSorted)
        {
        ...
        editor = html.Editor(fieldname, new { htmlAttributes = new { @class = "form-control", style = "max-width:200px;min-width:100px" } });

        all.AppendLine(AddOpenImageFunc(editor, fieldname));
...
}
return all;