Tag: asp.net mvc

由于Web API中的特殊字符,未设置发布值

我正在尝试为我的网络API服务发帖。 重点是发送消息时 { message: “it is done” } 工作正常。 但是当我在我的消息中使用像çıöpş这样的特殊字符时,它无法转换我的json以使post对象保持为null。 我能做什么? 这既是当前的文化问题,也可能是其他问题。 我试图将我的post参数发送为带有编码HttpUtility类的HtmlEncoded样式,但它也不起作用。 public class Animal{ public string Message {get;set;} } Web API方法 public void DoSomething(Animal a){ } 客户 Animal a = new Animal(); a.Message = “öçşistltl”; string postDataString = JsonConvert.SerializeObject(a); string URL = “http://localhost/Values/DoSomething”; WebClient client = new WebClient(); client.UploadStringCompleted += client_UploadStringCompleted; client.Headers[“Content-Type”] = […]

C# – ObjectContext实例已被释放,不能再用于需要连接的操作

我很抱歉重复。 我正朝着同样的问题前进,但仍无法处理它。 我正在使用Angularjs框架和Asp.net mvc。 我的class级: public partial class Person { public int PersonID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Telephone { get; set; } public string Adress { get; set; } public int UserID { get; set; } public virtual User […]

ASP MVC 5和Json.NET:动作返回类型

我正在使用ASP MVC 5.我在控制器中有一个返回json对象的动作: [HttpGet] public JsonResult GetUsers() { return Json(….., JsonRequestBehavior.AllowGet); } 现在我想使用JSON.Net库,我发现在ASP MVC 5中还存在。 实际上我可以写 using Newtonsoft.Json; 没有从NuGet导入库。 现在我试着写: public JsonResult GetUsers() { return JsonConvert.SerializeObject(….); } 但是我在编译期间出错:我无法将返回类型字符串转换为JsonResult。 我怎样才能在动作中使用Json.NET? 动作的正确返回类型是什么?

ASP.NET MVC5未针对请求的URL配置Web服务器,并且未在服务器上启用目录浏览

我有一个从MVC5应用程序加载页面的问题。 我安装并使用了这个软件: Windows 10 Visual Studio Enterprise 2015 Microsoft IIS 10.0 Express 带有entity framework的MVC 5 到现在为止一切正常,我能够显示网站。 在创建模型之后,使用entity framework的控制器之后我收到了此错误消息。 HTTP Error 403.14 – Forbidden The Web server is configured to not list the contents of this directory. Most likely causes: A default document is not configured for the requested URL, and directory browsing is not enabled […]

在创建新模型时上载图像

我将在ASP.Net MVC应用程序中为我的用户创建配置文件。 用户创建控制器是这样的: [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create(UserProfileViewModel userViewModel) { if (ModelState.IsValid) { …. } return View(userViewModel); } 此外,每个用户模型都有几个属性,包括一张照片。 一切顺利,直到我想添加一个输入字段来接受照片。 @Html.TextBoxFor(model => model.ImageUrl, new { type = “file” }) 我将以下字段添加到UserProfileViewModel : [Display(Name = “Profile Photo”)] public HttpPostedFileBase ImageUrl { get; set; } 在上传照片的片段和我上一个问题的答案中,似乎上传照片被视为一项单独的任务。 即我需要一个单独的表格和控制器来上传照片( 就像这个答案的第一部分 )。 我想知道是否有任何方法可以在一个表单中创建整个用户配置文件并将其照片传递给同一个控制器(其中包括UserProfileViewModel照片)? 我需要注意我不知道使用jQuery或AJAX,我想使用标准的HTML帮助程序来完成这项任务。 更新:我的视图看起来像这样: @model ProjectManager.Models.UserProfileViewModel @{ ViewBag.Title = “Create”; […]

无法使用Simple Injector注册Api控制器?

我有一个使用Simple Injector的WebApi,它工作得非常好,但我必须在项目中实现OAuth。 现在我已经这样做了,我的ApiControllers给了我一个像Simple Injector这样的错误,现在已经正确设置了 我有我的Start.cs文件 public class Startup { public void Configuration(IAppBuilder app) { // Web API configuration and services HttpConfiguration config = new HttpConfiguration(); Container container = SimpleInjectorConfig.Initialize(app); ConfigureAuth(app, container); WebApiConfig.Register(config); app.UseWebApi(config); } public void ConfigureAuth(IAppBuilder app, Container container) { var OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString(“/token”), AccessTokenExpireTimeSpan […]

将validation附加到MVC控制器/视图中使用的EF对象?

我们正在组合一个快速项目(CRUD表单)并决定跳过视图模型并直接在控制器和视图中使用EF实体。 由于我不习惯这种方法,我对处理validation感到困惑。 例如:DB字段的长度为25.如何在我的视图中将其转移(如果可以)到validation约束? 如果我使用的是中间模型,我会将属性附加到模型属性,它会起作用。 我如何直接使用EF对象? 谢谢。

为什么我可以使用简写“而不是实际类的名称,“?

我正在浏览ASP.NET Web堆栈源代码,并注意到AuthorizateAttribute类实际上是这样命名的( 参见此处 )。 那么,为什么我可以使用[Authorize]来应用属性……但这并不是Class的名称。 该类的名称是AuthorizateAttribute 。 我实际上将代码复制/粘贴到我自己的解决方案中,并将该类重命名为JeffthorizeAttribute ,并且我不能将[Jeffthorize]属性添加到我的MVC控制器中。 为什么它接受缩短的版本而不是完整的类名? 父属性类中是否存在自动计算出来的内容? 只是想了解:(

如何使用MVC.Net建模绑定“List ”列表

我正在尝试创建一个由一系列下拉列表组成的表单,所有这些列表都是从数据库加载的。 我不知道需要多少下拉列表,或者每个下拉列表在编译时有多少选项。 如何设置这些字段以允许它们在发布时进行模型绑定? 在下面的每个代码元素中都有很多其他的复杂性,但是即使在降低到​​基本级别时,我也无法使模型绑定工作。 型号: public class MyPageViewModel { public List ListOfDropDownLists { get; set; } } public class MyDropDownListModel { public string Key { get; set; } public string Value { get; set; } public List Options { get; set; } } 控制器获取操作: [AcceptVerbs(HttpVerbs.Get)] [ActionName(“MyAction”)] public ActionResult MyGetAction() { var values_1 = new List […]

SignalR聊天应用程序发送图像

我从教程中构建了SingnalR聊天应用程序MVC5 signalR 2.0: – http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-getting-started- with-signalr-20-and-mvc-5虽然有办法发送图像/附件,但它的工作都非常出色吗? 和实际显示在屏幕上的图像?