Tag: asp.net mvc 4

Viewbag RuntimeBinderException:’object’不包含定义

如何通过ViewBag解决此错误将数据传递给视图? System.Core.dll中出现“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”类型的exception,但未在用户代码中处理 附加信息:’object’不包含’name’的定义 在控制器中 var linq = (from c in db.Catogeries join a in db.Articals on c.Id equals a.CatogeryId select new {name=c.Name,title=a.Title }); ViewBag.data = linq; 在视图中 @{ foreach (var item in ViewBag.data ) { @item.name } }

错误:项目上未安装EntityFramework包

我刚刚安装了SQL Server 2008,将我的ASP.NET MVC 4项目配置为部署在本地IIS,并添加了一个新的连接到数据库(在sql server 2008中)。 当我尝试通过Package Manager控制台中的 Enable-Migrations -ContextTypeName MonitoringNDataContext启用迁移(entity framework)时。 我得到以下错误: 项目’MonitoringN.Tests’上未安装EntityFramework包。 请问有什么好主意吗? MonitoringN:命名ASP.NET MVC 4项目。 MonitoringNDataContext:放入MonitoringN的我的DBContext类的名称。 MonitoringN.Tests:与MonitoringN相关的unit testing项目的名称。

如何退出会议MVC Razor视觉工作室

我正试图从MVC Razor中的会话注销,这是我目前在MainController中的内容: [HttpPost] public ActionResult Login(Users user) { if (ModelState.IsValid) { if (ValidateUser(user.Email, user.Password)) { FormsAuthentication.SetAuthCookie(user.Email, false); return RedirectToAction(“Index”, “Members”); } else { ModelState.AddModelError(“”, “”); } } return View(); } private bool ValidateUser(string Email, string Password) { bool isValid = false; using (var db = new ShareRideDBEntities()) { var User = db.tblProfiles.FirstOrDefault(u => u.PROF_Email == […]

SignalR 2.0.2创建PersistentConnection

我使用包管理器控制台将SignalR 2.0.2安装到我的MVC 4.5应用程序中。 我做了连接配置的标准示例。 namespace SignalRPersistent { public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(“/echo”); } } } 问题是MapSignalR方法不接受字符串,而编译错误则说明了这一点 参数类型字符串不能分配给参数类型SignalRHubConfiguration。 但我可以看到一个接受字符串的重载方法,但它坚持不编译。 有什么问题?

在自托管WebApi中获取HttpRequest上下文

如何从自托管的MVC WebAPI访问查询字符串? 使用NRE调用以下失败,因为Current为空(aka。null) System.Web.HttpContext.Current.Request[“myQuery”] 我需要访问控制器外部的当前上下文,因为我想通过控制我的对象实例化。 DI。 例如。 container .RegisterType( new InjectionFactory( uc => new MyObject( System.Web.HttpContext.Current.Request[“myParam”]) //This failed. )); 由于上面的NRE,从ControllerApi代码内部调用container.Resolve()失败。

确保控制器在Unity中具有无参数的公共构造函数

我在控制器中遇到了这个问题: 尝试创建类型为“ * .WebMvc.Controllers.HomeController”的控制器时发生错误。 确保控制器具有无参数的公共构造函数。 找到ApiController的解决方案,但没有找到任何关于普通控制器的信息。 从头开始创建新的MVC 4项目。 HomeController.cs: public class HomeController : Controller { private IAccountingUow _uow; public HomeController(IAccountingUow uow) { _uow = uow; } UnityDependencyResoler.cs: public class UnityDependencyResolver : IDependencyResolver { private IUnityContainer _container; public UnityDependencyResolver(IUnityContainer container) { _container = container; RegisterTypes(); } public object GetService(Type serviceType) { try { return _container.Resolve(serviceType); }catch […]

无法从Azure网站访问Azure数据库服务器

我使用Visual Studio 2013 Web Express创建了一个MVC Web应用程序。 我已在Azure中为我的计算机启用了防火墙规则,我可以从本地计算机连接并远程调试我的网站。 我有用户SQL Server对象资源管理器,以确认我正在连接到我的Azure数据库,并确保应用程序正常运行。 但是,当我将应用程序部署到Azure时,我收到以下连接错误。 我已经检查过以确保该网站将Azure数据库作为链接资源。 我使用FTP连接到网站并确认我的web.config中的连接字符串是否正确。 这似乎是我的Azure设置中的一些配置问题,但我不知道还有什么要检查。 任何建议表示赞赏。 —————收到错误(用户名和跟踪ID已更改)————————- – ‘/’应用程序中的服务器错误。 用户’MyUserName’登录失败。 已为此会话分配了跟踪ID“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”。 在需要帮助时,请将此跟踪ID提供给客户支持。 描述:执行当前Web请求期间发生未处理的exception。 请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。 exception详细信息:System.Data.SqlClient.SqlException:用户’MyUserName’登录失败。 已为此会话分配了跟踪ID“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”。 在需要帮助时,请将此跟踪ID提供给客户支持。 来源错误: 在执行当前Web请求期间生成了未处理的exception。 可以使用下面的exception堆栈跟踪来识别有关exception的起源和位置的信息。 堆栈跟踪: [SqlException (0x80131904): Login failed for user ‘MyUserName’. This session has been assigned a tracing ID of ‘xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx’. Provide this tracing ID to 客户支持时需要帮助。] System.Data.SqlClient.SqlInternalConnection.OnError(SqlExceptionexception,Boolean breakConnection,Action 1 […]

为什么viewbag值没有传回视图?

直截了当的问题,似乎无法让我的viewBag值显示在完成表单后用户指向的视图中。 请指教..谢谢 我的索引ActionResult简单返回模型数据.. public ActionResult Index() { var source = _repository.GetByUserID(_applicationUser.ID); var model = new RefModel { test1 = source.test1, }; return View(model); } 我的获取编辑“ActionResult,只使用与索引相同的模型数据。 我的post“编辑”ActionResult,将新值分配给模型并重定向到索引页面,但索引页面不显示ViewBag值? [HttpPost] public ActionResult Edit(RefModell model) { if (ModelState.IsValid) { var source = _repository.GetByUserID(_applicationUser.ID); if (source == null) return View(model); source.test1 = model.test1; _uow.SaveChanges(); @ViewBag.Message = “Profile Updated Successfully”; return […]

初始化DateTime时的exception

我在控制器操作的参数中初始化DateTime变量,如下所示 public ActionResult ForFahrzeug(DateTime initDat = default(DateTime), long id = 0, long days = 0, string ExpGnr = “”) { //body } 编译时没有错误,但在运行时发生exception。 Server Error in ‘/’ Application. Encountered an invalid type for a default value. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for […]

在MVC中声明html助手时,如何用破折号创建html属性?

例如,当我声明和Html.TextboxFor帮助器时,我如何创建data-bind属性? 简单地做: @Html.TextBoxFor(model => model.SomeProperty, new { data-bind=”something” }) 由于带有短划线“ – ”符号的命名问题,这是不合法的。 有没有办法解决这个问题,或者只是不可能传递名称包含破折号的html属性? 注意:我尝试拍打@ (这有助于你想在属性前面传递一个与C#保留字匹配的属性,比如“class”),但是没有做到这一点……