Xamarin ASP mvc 4動作,參數不起作用

[英]Xamarin ASP mvc 4 action with parameters not working


I have these actions:

我有這些行動:

public class HomeController : Controller
    {
        public ActionResult Index ()
        {
            ViewData ["Message"] = "Welcome to ASP.NET MVC on Mono!";
            return View ();
        }


        public ActionResult Pages (string test)
        {
            ViewBag.Message = test;
            return View ();
        }


    }

The pages action is not working. I get an error 500:

頁面操作無效。我收到錯誤500:

System.TypeLoadException
Could not load type 'System.Web.UnvalidatedRequestValuesBase' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Description: HTTP 500.Error processing request.

Details: Non-web exception. Exception origin (name of application or object): System.Web.Mvc.
Exception stack trace:
at System.Web.Mvc.FormValueProviderFactory.GetValueProvider (System.Web.Mvc.ControllerContext controllerContext) [0x00000] in <filename unknown>:0 at System.Web.Mvc.ValueProviderFactoryCollection.GetValueProvider (System.Web.Mvc.ControllerContext controllerContext) [0x00000] in <filename unknown>:0 at System.Web.Mvc.ControllerBase.get_ValueProvider () [0x00000] in <filename unknown>:0 at System.Web.Mvc.ControllerActionInvoker.GetParameterValue (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ParameterDescriptor parameterDescriptor) [0x00000] in <filename unknown>:0 at System.Web.Mvc.ControllerActionInvoker.GetParameterValues (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionDescriptor actionDescriptor) [0x00000] in <filename unknown>:0 at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass21.<BeginInvokeAction>b__19 (System.AsyncCallback asyncCallback, System.Object asyncState) [0x00000] in <filename unknown>:0 

If I remove the parameter from that action is working fine.

如果我從該操作中刪除參數工作正常。

Any ideas?

有任何想法嗎?

Thanks in advance!

提前致謝!

p.s. I don't have any routes defined yet.

附:我還沒有定義任何路線。

3 个解决方案

#1


7  

Using newest mono(3.6.1) doesn't resolve issue. What helps is: If you're using 5.X NuGet Microsoft ASP.NET MVC package, downgrade to MVC 4 is required.

使用最新的單聲道(3.6.1)無法解決問題。有用的是:如果您使用的是5.X NuGet Microsoft ASP.NET MVC軟件包,則需要降級到MVC 4。

Steps:

  1. Uninstall following NuGet packages(order is important):
    • Microsoft.AspNet.WebPages
    • Microsoft.AspNet.WebPages
    • Microsoft.AspNet.Razor
    • Microsoft.AspNet.Razor
    • Microsoft.AspNet.Mvc
    • Microsoft.AspNet.Mvc
  2. 在NuGet包之后卸載(順序很重要):Microsoft.AspNet.WebPages Microsoft.AspNet.Razor Microsoft.AspNet.Mvc
  3. Install Microsoft ASP.NET MVC 4 NuGet package.
  4. 安裝Microsoft ASP.NET MVC 4 NuGet包。

Errors that may occur:

  • The view 'Index' or its master was not found.
    • Solution - change version of System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc in /Views/Web.Config in factoryType attribute of host node to 4.0.0.0. So line looks like this:
    • 解決方案 - 將主機節點的factoryType屬性中的/Views/Web.Config中的System.Web.Mvc.MvcWebRazorHostFactory,System.Web.Mvc的版本更改為4.0.0.0。所以行看起來像這樣:
  • 未找到“索引”視圖或其主頁。解決方案 - 將主機節點的factoryType屬性中的/Views/Web.Config中的System.Web.Mvc.MvcWebRazorHostFactory,System.Web.Mvc的版本更改為4.0.0.0。所以行看起來像這樣:

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

  • System.InvalidOperationException Conflicting versions of ASP.NET Web Pages detected: specified version is “3.0.0.0”, but the version in bin is “2.0.0.0”. To continue, remove files from the application’s bin directory or remove the version specification in web.config.
    • Solution - change webpages:Version to 2.0.0.0 in Root directory/Web.Config so it looks like this: <add key=”webpages:Version” value=”2.0.0.0” />
    • 解決方案 - 將根目錄/ Web.Config中的版本更改為2.0.0.0,使其如下所示:
  • System.InvalidOperationException檢測到的ASP.NET網頁的沖突版本:指定版本為“3.0.0.0”,但bin中的版本為“2.0.0.0”。要繼續,請從應用程序的bin目錄中刪除文件,或刪除web.config中的版本規范。解決方案 - 將根目錄/ Web.Config中的版本更改為2.0.0.0,使其如下所示:

Then you can use parameters in controller actions.

然后,您可以在控制器操作中使用參數。

#2


1  

This is embarrassing, but here is my workaround until Mono updates System.Web:

這是令人尷尬的,但這是我的解決方法,直到Mono更新System.Web:

public ActionResult Index() //string app_id, string session_id, int surah_id, int ayat_id)
{
    string app_id = Request["app_id"];
    string session_id = Request["session_id"];
    int surah_id = Int32.Parse(Request["surah_id"]);
    int ayat_id = Int32.Parse(Request["ayat_id"]);

    // ...
}

#3


1  

I got the same error as OP in my MVC-project. (Currently using Xamarin on a Mac) I'm using Microsoft Exchange WebServices, and I found out that downgrading this package solved my problem. I downgraded the Microsoft.Exchange.Webservices package from 2.2 to 1.2.

我在MVC項目中遇到了與OP相同的錯誤。 (目前在Mac上使用Xamarin)我正在使用Microsoft Exchange WebServices,我發現降級此軟件包解決了我的問題。我將Microsoft.Exchange.Webservices包從2.2降級到1.2。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/02/17/7256fbd599c6d22ea68da6adab5a0ab9.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com