繁体   English   中英

无法将 lambda 表达式转换为类型对象,因为它不是委托类型

[英]cannot convert lambda expression to type object because it is not a delegate type

我有一个从 Web API 返回 json 对象的 GET 方法。 我已经创建了相应的模型。 当我尝试将值放入视图时,出现此错误:

无法将 lambda 表达式转换为类型对象,因为它不是委托类型

我需要从模型中获取 location 属性的值。

控制器:

public IActionResult AddEditLoadBalancer(string subscriptionId, string resourceGroupName, string loadBalancerName, string subscriptionName)
{
    try
    {
        ViewBag.LBName = loadBalancerName;
        ViewBag.SubscriptionName = subscriptionName;
        var token = HttpContext.Session.GetString("Token");
        var tenantid = HttpContext.Session.GetString("TenantId");

        var sessionId = HttpContext.Session.GetString("SessionId");
        if (!string.IsNullOrEmpty(token) || !string.IsNullOrEmpty(tenantid))
        {
            var path = $"/api/PaasCatalog/AddEditLoadBalancer?subscriptionId=" + subscriptionId + "&resourceGroupName=" + resourceGroupName + "&loadBalancerName=" + loadBalancerName;
            var response = _httpClient.SendRequestWithBearerTokenAsync(HttpMethod.Get, path, null, token, tenantid, _cancellationToken, sessionId).Result;
            if (!response.IsSuccessStatusCode)
                return null;
            var result = response.Content.ReadAsStringAsync().Result;
            if (result == null)
                return null;
            var jsontemplates = JsonConvert.DeserializeObject<AddEditLoadBalancer>(result);

            return View(jsontemplates);
        }
        else
        {
            RedirectToAction("SignOut", "Session");
        }
    }
    catch (Exception ex)
    {
        _errorLogger.LogMessage(LogLevelInfo.Error, ex);
        return null;
    }
    return null;
}

看法:

<div class="form-group">
    <label class="col-md-2 control-label">Location:</label>
    <div class="col-md-4">
        @Html.EditorFor(x => x.location, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
    </div>
</div>

我哪里错了? 请帮我。 谢谢你。

代码中的一切都是正确的。 我所要做的就是清理并重建整个应用程序并停止所有正在运行的工作进程。 这解决了我的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM