ASP.NET 5中System.Web.Mvc.Html.InputExtensions的等价物是什么?

时间:2015-10-27 07:44:44

标签: c# html-helper asp.net-core asp.net-core-mvc

ASP.NET 4中使用的ASP.NET {5 {1}}是什么?

见下面的例子:

System.Web.Mvc.Html.InputExtensions

1 个答案:

答案 0 :(得分:3)

对于ASP.NET 4代码:

if (cluster.isMaster) {
    // Create a worker for each CPU
    global.my_cache_variable = 'xyz';
    console.log("Number of cpu cores", cCPUs);
    for (var i = 0; i < cCPUs; i++) {
        cluster.fork();
    }

    cluster.on('online', function (worker) {
        console.log('Worker ' + worker.process.pid + ' is online.');
    });
    cluster.on('exit', function (worker, code, signal) {
        console.log('worker ' + worker.process.pid + ' died.');
        cluster.fork();
    });
} else {
   //create server code here
   // and access the global cache variable with the workers
}

ASP.NET 5的等价物是:

    MvcHtmlString html = 
        System.Web.Mvc.Html.InputExtensions.TextBoxFor(
            htmlHelper, expression);

或包含在页面中的命名空间

Microsoft.AspNet.Mvc.Rendering.HtmlString html = 
     (Microsoft.AspNet.Mvc.Rendering.HtmlString)    
         Microsoft.AspNet.Mvc.Rendering.HtmlHelperInputExtensions.TextBoxFor(
             htmlHelper, expression);

它的内容如下:

@Microsoft.AspNet.Mvc.Rendering;

请注意,它的返回类型是接口HtmlString html = (HtmlString)HtmlHelperInputExtensions.TextBoxFor(htmlHelper,expression); ,而不是ASP.NET 4中的IHtmlContent

在ASP.NET 5中,

MvcHtmlString已替换为MvcHtmlString

由于HtmlString的{​​{1}}接口已退回而非IHtmlContent本身,您必须将返回值转换为HtmlString

但是,您希望将其用作ASP.NET 5中的扩展方法 因此,您应该将方法返回类型更改为HtmlString,将代码更改为:

HtmlString

可以找到源代码here