Tag: asp.net mvc 4

从PostAsJsonAsync获取响应

我有这行代码 var response = new HttpClient().PostAsJsonAsync(posturi, model).Result; 被调用的WebAPI控制器返回一个bool以确保该对象已保存,但如何返回该bool响应?

在bundleconfig中添加bootstrap在asp.net mvc中不起作用

我遇到了一个问题,在我看来很奇怪。 我通过nuget包控制台安装了bootstrap。 之后,在BundleConfig.cs文件中,我向bundles列表中添加了两个项: bundles.Add(new ScriptBundle(“~/bundles/bootstrap”).Include( “~/Scripts/bootstrap.min.js”)); bundles.Add(new StyleBundle(“~/Content/bootstrap”).Include( “~/Content/bootstrap.min.css”, “~/Content/bootstrap-theme.min.css”)); 当然,这些文件存在于本地。 _Layout.cshtml文件包含 @ViewBag.Title @Styles.Render(“~/Content/css”) @Scripts.Render(“~/bundles/modernizr”) @Styles.Render(“~/Content/bootstrap”) @RenderBody() @Scripts.Render(“~/bundles/jquery”) @Scripts.Render(“~/bundles/bootstrap”) @RenderSection(“scripts”, required: false) 但是当我看到一个视图(例如登录页面)时,我看到该bundle没有附加bootstrap部分。 Login …

ObjectContext实例已被释放,不能再用于需要连接的操作。 在参考表中

我有两个表Customers和Country and use(Entity Framework with vs 2012) 和模型类 using System; using System.Collections.Generic; public partial class Customer { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Address { get; set; } public string Email { get; set; } public string Phone […]

将对象传递给AutoMapper映射

我正在使用AutoMapper,正在映射的实体的一些值是我当前方法中的变量。 我试过谷歌它但无济于事。 我可以将一组KeyValue对或一个对象或东西传递给我的映射以使其使用这些值吗? 后映射修改的示例 //comment variable is a Comment class instance var imageComment = AutoMapper.Mapper.Map(comment); //I want to pass in imageId so I dont have to manually add it after the mapping imageComment.ImageId = imageId;

MVC 4 ViewModel没有被发送回Controller

我似乎无法弄清楚如何将整个ViewModel发送回控制器到’validation和保存’function。 这是我的控制器: [HttpPost] public ActionResult Send(BitcoinTransactionViewModel transaction) { } 以下是视图中的表单: Transaction Id @Html.DisplayFor(m => m.Transaction.TransactionId) Deposited Amount @Model.Transaction.Amount.ToString() BTC Time @Model.Transaction.Time.ToString() @using (Html.BeginForm(“Send”, “DepositDetails”, FormMethod.Post, new { transaction = Model })) { @Html.HiddenFor(m => m.Token); @Html.HiddenFor(m => m.Transaction.TransactionId); @Html.TextBoxFor(m => m.WalletAddress, new { placeholder = “Wallet Address”, maxlength = “34” }) @Html.ValidationMessage(“walletAddress”, new { @class […]

ASP.NET WebAPI + Soap

WebAPI是否支持SOAP? 我正在尝试在MVC4中编写SOAP服务器,虽然我可以在WCF中完成,但似乎WebAPI正在取代它,但我认为没有办法在此使用SOAP,只使用REST Style接口的JSON / XML。

堆栈跟踪如何指向错误的行(“返回”语句) – 40行关闭

我有两次现在看到从Production ASP.NET MVC 4 Web应用程序记录的NullReferenceException – 并且登录错误的行。 没有错误的一两行(就像你得到的PDB不匹配),但错误的是整个控制器动作的长度。 例: public ActionResult Index() { var someObject = GetObjectFromService(); if (someObject.SomeProperty == “X”) { // NullReferenceException here if someObject == null // do something } // about 40 more lines of code return View(); // Stack trace shows NullReferenceException here } 对于同一控制器上的操作,这发生了两次。 第二个案例已登录 // someObject is known […]

自定义模型Binderinheritance自DefaultModelBinder

我正在尝试为MVC 4构建一个自定义模型绑定器,它将inheritance自DefaultModelBinder 。 我希望它拦截任何绑定级别的任何接口,并尝试从名为AssemblyQualifiedName的隐藏字段加载所需的类型。 这是我到目前为止(简化): public class MyWebApplication : System.Web.HttpApplication { protected void Application_Start() { ModelBinders.Binders.DefaultBinder = new InterfaceModelBinder(); } } public class InterfaceModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (bindingContext.ModelType.IsInterface && controllerContext.RequestContext.HttpContext.Request.Form.AllKeys.Contains(“AssemblyQualifiedName”)) { ModelBindingContext context = new ModelBindingContext(bindingContext); var item = Activator.CreateInstance( Type.GetType(controllerContext.RequestContext.HttpContext.Request.Form[“AssemblyQualifiedName”])); Func modelAccessor = () => […]

ASP.MVC HandleError属性不起作用

我知道这是一个常见问题,但我已经抓住了许多讨论而没有结果。 我正在尝试使用HandleError ASP.MVC attrbiute来处理错误。 我正在使用MVC 4。 我的错误页面位于Views / Shared / Error.cshtml中,看起来像这样: Test error page Error. An error occurred while processing your request. App-Start文件夹中的My FilterConfig.cs是: public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } } 我的控制器: public class TestController : Controller { [HandleError(View = “Error”)] public ActionResult Index() { throw new Exception(“oops”); […]

我们可以使用代码优先迁移来运行SQL脚本吗?

我们可以使用代码优先迁移来运行sql脚本吗? 我是新手代码,如果我想在update-database命令迁移之前将我的更改保存到SQL脚本文件,是否可能? 如果可能,请提供完成工作的步骤。 此外,如果生成脚本,那么我是否可以使用迁移运行该脚本?