asp.net-mvc 相关问题

ASP.NET MVC框架是一个开源Web应用程序框架和工具,它实现了针对Web应用程序定制的模型 - 视图 - 控制器(MVC)模式的版本,并构建在ASP.NET技术基础之上。

验证过程中检测到以下错误。 - 无法反序列化当前 JSON 对象(例如 {"name":"value"})

我有 asp.net core mvc 视图,我在 foreach 中显示输入值 这是查看代码 我有 asp.net core mvc 视图,我在其中显示输入值 foreach 这是查看代码 <div class="modal-body box-wrap"> <form role="form" novalidate class="form-validation" name="ServicePriceInformationsForm"> <input type="hidden" asp-for="Id" /> <input type="hidden" asp-for="ServiceId" /> <div class="form-group"> <label class="required-label">@L("Location")</label> <select class="form-control" required asp-for="LocationId"> <option value="">@L("SelectALocation")</option> @if (Model.LocationId.HasValue) { <option selected value="@Model.LocationId">@Model.LocationName</option> } </select> </div> <div class="form-group"> <label class="required-label">@L("MaterialUom")</label> <select class="form-control" asp-for="MaterialUomId" id="ServicePrice_MaterialUomId"> <option value="">Select an option</option> @if (Model.MaterialUomId > 0) { <option value="@Model.MaterialUomId">@Model.MaterialUomName</option> } </select> </div> <div class="form-group"> <label>@L("Cost")</label> <input class="form-control" type="text" asp-for="Cost" data-rule-number="true" data-rule-min="0" data-rule-max="@AppConsts.MaxDecimalDatabaseLength"> </div> @{ int i = 0; } @foreach (var tier in @Model.LocationServicePrices) { <div class="form-group"> <label>@tier.PricingTierName</label> <input class="form-control" type="text" asp-for="@tier.PricePerUnit" name="LocationServicePrices[@i].PricePerUnit" data-rule-number="true" data-rule-min="0" data-rule-max="@AppConsts.MaxDecimalDatabaseLength"> </div> i++; } </form> </div> 然后在JS中我像这样将数据传递给BE this.save = function() { if (!_$form.valid()) { _$form.showValidateMessage(); return; } var servicePrice = _$form.serializeFormToObject(); console.log(servicePrice); _modalManager.setBusy(true); _serviceService.editLocationService(servicePrice).done(function() { abp.notify.info('Saved successfully.'); _modalManager.close(); abp.event.trigger('app.createOrEditServicePriceModalSaved'); }).always(function() { _modalManager.setBusy(false); }); }; 浏览器中的控制台显示此 这是BE的模型 public class LocationServiceEditDto: EntityDto<int?> { public int ServiceId { get; set; } public int? LocationId { get; set; } public decimal? Cost { get; set; } public int? MaterialUomId { get; set; } public string MaterialUomName { get; set; } public string LocationName => Location?.Name; [JsonIgnore] public LocationNameDto Location { get; set; } public ICollection<LocationServicePriceDto> LocationServicePrices { get; set; } } 这是控制器 public async Task EditLocationService(LocationServiceEditDto input) { var locationServices = new List<LocationServicePrice>(); if (input.LocationServicePrices.Count > 0) { locationServices = input.LocationServicePrices.Select(x => new LocationServicePrice() { LocationServiceId = x.LocationServiceId, PricingTierId = x.PricingTierId, PricePerUnit = x.PricePerUnit }).ToList(); } await _locationServiceRepository.InsertOrUpdateAndGetIdAsync(new LocationService { Id = input.Id ?? 0, ServiceId = input.ServiceId, LocationId = input.LocationId, Cost = input.Cost, UnitOfMeasureId = input.MaterialUomId, LocationServicePrices = locationServices }); } 生成的JSON是: { "Id": "", "ServiceId": "2031", "LocationId": "2", "MaterialUomId": "6", "Cost": "123", "LocationServicePrices": { "0.PricePerUnit": "1", "1.PricePerUnit": "2", "2.PricePerUnit": "3", "3.PricePerUnit": "4", "4.PricePerUnit": "5" } } 当我单击“保存”时,出现此错误 我该如何解决这个问题? 问题出在序列化上。 一个简单的解决方法是将对象设置为像这样的数组。 var servicePrice = _$form.serializeFormToObject(); servicePrice.LocationServicePrices = Object.values(servicePrice.LocationServicePrices) .map(elm => +elm); console.log(servicePrice); P.S:基于假设 LocationServicePrices 需要一个 int 数组(来自错误消息的屏幕截图)。

回答 1 投票 0

ASP.NET MVC 读取原始 JSON Post 数据

我正在使用 ASP.NET MVC。我有一个带有 HttpPost 操作的控制器,该操作充当由另一台服务器(不在我的控制之下)调用的回调 URL。我想动态读取发布到它的 JSON

回答 3 投票 0

c# 方法返回 HTML 字符串的格式问题

我有一个 C# 方法,它返回包含 HTML 标记的字符串文字。最初,我硬编码了一个 URL,但现在我想生成一个动态 URL。但是,我遇到了错误,可能是由于

回答 1 投票 0

网站中的userIdInt、commentid等是否应该加密?

我目前正在网页上显示其中一些 commentid 和 userIdInt (也许还有其他内容!)(不是直接显示,但如果您点击“查看源代码”)...我应该加密它们吗?我想加密使用...

回答 3 投票 0

如何使用 DI 在类构造函数中获取 Microsoft.AspNet.Http.HttpContext 实例

我正在 MVC 6 中构建一个一次性应用程序,并尝试不同的依赖架构。 我面临的问题是如何创建特定于...的自定义“MyAppContext”对象

回答 4 投票 0

ASP.NET MVC Kendo Grid 在折叠具有聚合的组时抛出异常

我有网格用于显示数据库中的数据。它具有分组功能,现在我添加一个聚合函数 - 双字段求和。 而且效果很好。我可以对网格中的字段进行分组,并将 Sum 应用于字段。 ...

回答 1 投票 0

asp.net mvc 5 'ModelType' 未声明

我最近对我的两个项目进行了 NuGet 包更新。所以我使用 Microsoft.AspNet.Mvc 版本 5.2.0。一个项目运行良好,另一个项目则有些不正常,因为我现在不能

回答 6 投票 0

如何验证 AmazonAWS 是否正在创建非正版点击?

我有一个网站,每当用户提出详细信息时,都会记录“点击(通过将记录保存到点击表,该表在加载详细信息页面时捕获计算机的日期/时间和 IP)”

回答 1 投票 0

AmazonAWS 是否正在创造非正版点击?如何验证?

我有一个网站,每当用户提出详细信息时,都会记录“点击(通过将记录保存到点击表,该表在加载详细信息页面时捕获计算机的日期/时间和 IP)”

回答 1 投票 0

将编辑后的集合写入后端(ASP.NET core MVC)

我有一个 Razor 模式,可以从 BE 获取数据 这是模型 公共类 LocationServiceEditDto:EntityDto { 公共 int ServiceId { 获取;放; } 公共整数?位置Id { 获取;...

回答 1 投票 0

根据变量切换隐藏文本

我想根据上一页表单的输入显示多个文本。 例如,如果他们的答案满足某些标准,在控制器中我将制作 TestElig...

回答 1 投票 0

如何在不使用ajax的情况下从html中名称为数组的输入将数组名称传递给控制器,只需将其传递给控制器参数

<div class="col-md-3 ingname"> <input class="form-control ingredient-name" placeholder="Ingredient Name" id="ingredientName[]" name="ingredientName[]" required /> </div> <div class="col-md-3 ingqty"> <input class="form-control ingredient-quantity" placeholder="Quantity" type="number" min="0" id="ingredientQty[]" name="ingredientQty[]" required/> </div> 如何将这些输入传递给控制器 这是正确的吗? public ActionResult UploadRecipe(Recipe recipe, string ingcount, string moodid, string[] ingredientName, int[] ingredientQty, string[] ingredientUnit) { 显然,您只能在 html 输入标签中绑定这些数据类型。 通过从输入名称中删除 [],您可以获取控制器中的值。 但是你不能直接在控制器中获取字符串或整数数组。您可以做的是使用 JSON.stringify(arr) 将数组转换为字符串并将其与文本输入绑定,然后将其转换回控制器中的数组。

回答 1 投票 0

创建一个从 Mock 继承属性的类。 C#

我想创建一个继承Mock属性的类。这样,当我调用它时,我可以无缝地使用设置方法和其他功能 这是我的班级 公开课

回答 1 投票 0

如何在 ASP NET MVC 中自定义不显眼的验证 JQuery 消息?

我有一个表单,当它进行不显眼的验证时,我希望它显示: 此消息:“请输入一个值。” 而不是这条消息:“此字段是必填的。” 我尝试在...

回答 3 投票 0

如何将引导主题/示例添加到 ASP.NET MVC 5 中?

我正在开发一个 ASP.NET MVC 项目,我必须将引导主题/示例放入项目中,但我不知道如何操作。 https://getbootstrap.com/docs/4.3/examples/dashboard/。我已经下载了.zi...

回答 1 投票 0

我无法在剃刀视图中设置断点

我知道可以在 MVC Razor 视图中设置断点,但出了点问题,它不再工作了。 我尝试重新启动 Visual Studio 2013 并更改调试的一些选项。哈...

回答 4 投票 0

视图上的格式文档插入“ExternalSource”指令

我最近在 Visual Studio (2015 Enterprise) 中注意到一个问题,当我处理视图时,我通过键盘使用“格式化文档”功能来格式化文档

回答 2 投票 0

如何使用反向代理正确处理url(.net core views/home/* location 404错误)

我目前正在该域上使用 PHP Web 服务。 (例如)www.mydomain.com 我还在制作一个英文网站并将其设为.net core web 服务, 但我打算将其替换为 .net core inste...

回答 1 投票 0

无法获取dotnet6 MVC应用程序中ViewData中的所有字段

我正在开发一个 .net6 mvc 应用程序。 jquery 版本 1.8.3。 在我的控制器中我有这一行: ViewData["CountryState"] = new SelectList(countryStates, "PK_StateID",...

回答 1 投票 0

快速开发是 ASP.NET MVC 中的一个有争议的问题吗?

既然asp.net mvc取消了webform中的许多控件,这是否使得快速应用程序开发与现在的其他环境相同?例如,如果我有一个 php 中的 mvc 框架,...

回答 6 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.