无法找到Razor Host Factory类型(ASP.NET WEB MVC)

时间:2018-04-10 06:03:12

标签: c# asp.net asp.net-mvc web

我一直试图解决这个剃刀形式错误一周,我似乎无法修复它。

Microsoft.AspNet.MVC(版本5.2.4)

M.AspNet.Razor(版本3.2.4)

M.AspNet.WebPages(版本3.2.4)

M.Web.Infrastructure(版本1.0.0.0)

Newtonesoft.Json(版本11.0.2)

System.Net.Http(版本4.3.3)

Packages Screenshot

HomeController.cs(代码)

public async Task<ActionResult> Index()
    {
        PrimeCommand PCommand = new PrimeCommand();

        var responseString = await PCommand.Login("user", "pass", "api");
        ViewBag.SessionId = responseString;

        return View();
    }

登录()功能:

public async Task<string> Login(string username, string password, string apikey)
    {
        try
        {
            using (var httpClientHandler = new HttpClientHandler())
            {

                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; // PJDS code
                using (var client = new HttpClient(httpClientHandler))
                {

                    var newLogin = new LoginObject();

                    newLogin.ApplicationKey = apikey;
                    newLogin.UserName = username;
                    newLogin.Password = password;

                    var contentObject = JsonConvert.SerializeObject(newLogin);
                    var content = new StringContent(contentObject);

                    var response = await client.PostAsync(Api.base_url + "/Login", content);
                    var responseString = await response.Content.ReadAsStringAsync();
                    dynamic responseObject = JsonConvert.DeserializeObject(responseString);

                    var sessionID = responseObject.result.SessionID;

                    var searchObj = new SimpleSearchObject
                    {
                        SessionID = sessionID
                    };

                    return sessionID;
                }
            }
        }
        catch (Exception e)
        {
            Debug.WriteLine("error: login - " + e.Message);
            return null;
        }
    }

Index.cshtml

<form style="height: auto;width:300px;" action="action_page.php">
<div class="container">
        @using (Html.BeginForm())
{

   <b>@Html.LabelFor(x => x.UserName)</b>
    @Html.TextBoxFor(x => x.UserName)
    <br />

    <b>@Html.LabelFor(x => x.Password)</b>
    @Html.TextBoxFor(x => x.Password)

    <button type="submit" value="Index" name="action:Index">Login</button>


        <label>
            <input type="checkbox" checked="checked" name="remember"> Remember me
    </label>
}

    <span class="psw">Forgot <a href="#">password?</a></span>
</div>

错误

System.InvalidOperationException

找不到Razor Host Factory类型: System.Web.Mvc.MvcWebRazorHostFactory,System.Web.Mvc,Version = 5.2.0.0,Culture = neutral,PublicKeyToken = *******************

描述:HTTP 500.Error处理请求。

详细信息:非Web异常。异常来源(应用程序或对象的名称):System.Web.WebPages.Razor。

1 个答案:

答案 0 :(得分:0)

我将回答我的问题,问题出在我的Web.config文件而不是&lt; .... System.Web.Mvc,Version = 5.2.0.0 ...我的版本是5.2.3.0,我只是将零改为三。