Xamarin ASP mvc 4 操作参数不起作用 [英] Xamarin ASP mvc 4 action with parameters not working
本文介绍了Xamarin ASP mvc 4 操作参数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这些操作:
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 ();
}
}
页面操作不起作用.我收到错误 500:
The pages action is not working. I get an error 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.
有什么想法吗?
提前致谢!
附言我还没有定义任何路线.
p.s. I don't have any routes defined yet.
推荐答案
使用最新的 mono(3.6.1) 无法解决问题.有帮助的是:如果您使用的是 5.X NuGet Microsoft ASP.NET MVC 包,则需要降级到 MVC 4.
- 卸载以下 NuGet 包(顺序很重要):
- Microsoft.AspNet.WebPages
- Microsoft.AspNet.Razor
- Microsoft.AspNet.Mvc
可能出现的错误:
- 未找到视图索引"或其主视图.
- 解决方案 - 在
factoryType
/Views/Web.Config 中更改System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc
的版本>host
节点的属性为 4.0.0.0.所以线看起来像这样: - The view 'Index' or its master was not found.
- Solution - change version of
System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc
in /Views/Web.Config infactoryType
attribute ofhost
node to 4.0.0.0. So line looks like this: - System.InvalidOperationException 检测到 ASP.NET 网页版本冲突:指定版本为3.0.0.0",但 bin 中的版本为2.0.0.0".要继续,请从应用程序的 bin 目录中删除文件或删除 web.config 中的版本规范.
- 解决方案 - 将根目录/Web.Config 中的
webpages:Version
更改为 2.0.0.0,如下所示:<add key="webpages:Version" value="2.0.0.0"/>
- 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" />
然后你可以在控制器动作中使用参数.
Then you can use parameters in controller actions.
这篇关于Xamarin ASP mvc 4 操作参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Solution - change
- 解决方案 - 将根目录/Web.Config 中的
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
- Solution - change version of
Errors that may occur:
- 解决方案 - 在
查看全文