asp.net-mvc-4 相关问题

ASP.NET MVC 4是用于Web应用程序的ASP.NET Model-View-Controller平台的第四个主要版本。

从nuget升级到webgrease 1.5.1.25624后,出现System.IO.FileLoadException

我是asp.net死亡页面,这是我使用nuget升级了mvc4的webgrease和bootstrap之后出现的。 “/”应用程序中的服务器错误。 无法加载文件或程序集“WebGrease”或...

回答 6 投票 0

Dapper - 对象引用未设置到对象的实例

我最近一直在玩 dapper,但是在从其他表获取数据方面遇到了一些问题。 我的数据库有两个表,用户和帖子。我为

回答 1 投票 0

两个 ASP.NET MVC 应用程序覆盖相同的会话 cookie

我有两个带有会话配置的 ASP.NET MVC 应用程序。当我从app1登录时,登录成功。从app2登录后,覆盖app1的会话cookie并成功...

回答 1 投票 0

MVC 5 OWIN 使用声明和 AntiforgeryToken 登录。我是否错过了 ClaimsIdentity 提供商?

我正在尝试学习 MVC 5 OWIN 登录的声明。我尝试让它尽可能简单。我从 MVC 模板开始并插入我的声明代码(见下文)。当我使用 @H 时出现错误...

回答 7 投票 0

在 Asp.Net Core MVC 项目中未生成嵌套子子菜单

我正在尝试生成 3 级嵌套菜单,以便为我的应用程序创建导航栏。我写在下面的代码。但代码只返回顶部菜单和中间菜单。第三个菜单名为底部...

回答 1 投票 0

如何从Mvc中的控制器调用另一个控制器Action

我需要从控制器A调用控制器B操作FileUploadMsgView并需要为其传递一个参数。 它不会去控制器 B 的 FileUploadMsgView()。 这是代码: 控制器A:

回答 11 投票 0

使用ajax调用将模型作为列表从视图传递到控制器

我在尝试使用ajax调用发送实际上是一个List的整个模型时遇到了麻烦。 提供以下代码: @型号列表 我在尝试发送我的整个模型时遇到了麻烦,它实际上是使用 ajax 调用的List<Account>。 提供以下代码: @model List<ValidationAccount> <input type="button" id="SubmitAccounts" value="Final Proceed"> $("#SubmitAccounts").click(function () { $.ajax({ url: '/setupAccounts/ActivateAccounts', type: 'POST', contentType: 'application/json; charset=utf-8', cache: false, dataType: 'json', data: JSON.stringify(Model), success: function (data) { $(body).html(data); }, error: function (data) { } }); }); 我尝试过使用简单的 Model 和 @Model 但不起作用。在这种情况下我能做什么? (所以我想作为数据传递我的模型(我的列表))。 更新 方法签名: [HttpPost] public string ActivateAccounts(List<ValidationAccount> Accounts) { return "Success"; } 更新2 我的型号: public class ValidationAccount { public string Faculty { get; set; } public string Programme { get; set; } public string Year { get; set; } public string Email { get; set; } } 谢谢。 使用 @Model 将返回集合的名称,例如 "System.Collections.Generic.List[YourAssembly.ValidationAccount]",而不是集合中的对象。您可以将集合序列化到 ViewBag,然后将其发回(未测试),但双向发送数据似乎对性能造成不必要的影响。 相反,您可以将 Proceed 方法的过滤结果存储在会话中,并在 ActivateAccounts 方法中检索它,以避免发回任何内容。 这样做: data: { Accounts: JSON.stringify('@Model') } 并将 traditional 属性设置为 true: data: { Accounts: JSON.stringify('@Model') }, traditional:true 更新: var accounts= { Accounts: '@Model' }; 和: $.ajax({ type: 'POST', url: '/{controller}/{action}', cache: false, data: JSON.stringify(accounts), dataType: 'json', contentType: 'application/json; charset=utf-8' }); 您必须首先将数据解析为 json 尝试 var parsedData = @Html.Raw(Json.Encode(Model)); // This will change the model to json 然后将 parsedData 传递给 ajax 调用 $("#SubmitAccounts").click(function () { $.ajax({ url: '/setupAccounts/ActivateAccounts', type: 'POST', contentType: 'application/json; charset=utf-8', cache: false, dataType: 'json', data: parsedData, success: function (data) { $(body).html(data); }, error: function (data) { } }); }); 希望这有帮助。 将整个模型传递回控制器方法的最佳方法是序列化表单,如下所示... $(document).ready( function() { var form = $('#Form1'); $('#1stButton').click(function (event) { $.ajax( { type: "POST", url: form.attr( 'action' ), data: form.serialize(), success: function( response ) { console.log( response ); } } ); } ); } 注意:您用来触发导致通过ajax post提交表单的事件的按钮不应该是submit类型!否则这永远会失败。 在您的 .cshtml 中,导入 System.Text.Json,然后像 @JsonSerializer.Serialize(Model.ToList())) 一样使用它 @model IEnumerable<Ticket> @using System.Diagnostics; @using System.Text.Json; @if (Model.Count() > 0) { <div id="ticketGrid"> <table > <thead> // ... <th scope="col"> <span class="d-flex"> <button style="all:unset" onclick="toggleOrder(@JsonSerializer.Serialize(Model.ToList()))"> </button> @Html.DisplayNameFor(model => model.Issue.UpdatedOn) </span> </th> // ... </thead> <tbody height="80px" class="overflow-y-auto"> @foreach (var item in Model) { <tr scope="row"> // ... </tr> } </tbody> </table> </div> } 在 Ajax 中,使用 JSON.stringify(your-model) 和 contentType: 'application/json' <script> function toggleOrder(tickets) { $.ajax({ method: 'POST', url: '/Ticket/ToggleOrder', data: JSON.stringify(tickets), contentType: 'application/json', // dataType: 'json', success: function (viewData) { $("#ticketGrid").html(viewData); } }); }; </script> 在您的控制器中,使用 [HttpPost] public async Task<IActionResult> ToggleOrder([FromBody] List<Ticket> tickets) { // do something ... // return Json or PartialView // return Json(new { data = ticketsToReturn }); return PartialView("_TicketGrid", ticketsToReturn.ToList()); }

回答 5 投票 0

MVC Azure AD 授权角色

我在 MVC 中使用 [Authorize] 属性时遇到问题。 以下是采取的步骤: 创建名为 TestAD1 的 Azure Active Directory 在AD中插入多个用户 创建一个名为 TestGroup1 的组 使用

回答 1 投票 0

Ajax 函数不显示 JSON 日期列表 (Mvc5)

在我的 MVC5 视图中,我正在调用 JSON 函数。 JSON 函数返回一个AvailableDates 模型,其中定义了Userld(string) 和DateTime 对象的LIST。 我的视图只能读取用户...

回答 2 投票 0

ASPNET MVC 角色正在尝试使用 SQLServerExpress 而不是 SQLServer

我的 web.config 文件中有以下内容 我的 web.config 文件中有以下内容 <configuration> <connectionStrings> <add name="DefaultConnection" connectionString="Data Source=DESKTOP-6HOPM3U;Initial Catalog=DatabaseName;Integrated Security=True;Connect Timeout=15;" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration> 我可以做我需要做的一切,直到我添加基于角色的身份验证并将其添加到我的 _Layout.cshtml 文件中 @if(User.IsInRole("Admin")) { <li>@Html.ActionLink("Admin Menu","Index","Main",new{ area = "Admin"},null)</li> } 此时会抛出一个错误,提示 A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. SQLExpress database file auto-creation error: The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database: If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable automatic creation of the provider database. Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the application's App_Data directory does not already exist, the web server account must have read and write access to the application's directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist. If the application's App_Data directory already exists, the web server account only requires read and write access to the application's App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the application's App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server account's credentials are used when creating the new database. Sql Server Express must be installed on the machine. The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)] System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager) +947 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +6050103 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +531 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +156 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +22 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +92 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +219 System.Data.SqlClient.SqlConnection.Open() +101 System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +78 [HttpException (0x80004005): Unable to connect to SQL Server database.] System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +131 System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +92 System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +30 System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +410 当我删除线条时 if(User.IsInRole("Admin")) { } 它可以工作,但现在我没有基于角色的访问权限。 我没有使用 Sql Server Express。我需要更改什么才能使身份的基于角色的部分使用我的连接字符串中的数据库? 您遇到的错误表明与 SQL Server 建立连接时出现问题。如果您认为正确,请写信,以便我提供不同的解决方案。

回答 1 投票 0

对 IIS(MVC4 应用程序)的请求在到达控制器之前在管道内(在 ExtensionlessUrlHandler-Integrated-4.0 中)等待 10 秒

环境:IIS 7.5。 .NET 4.5.1。 WINDOWS 2008 R2 SP1 集成模式 我有一个在上述环境中工作的 MVC 应用程序。处理我的一些请求大约需要 15 秒。它没有...

回答 1 投票 0

Fluent 验证的正则表达式问题

可能是非常愚蠢的问题,但正在寻求帮助。 我正在向模型属性添加 MVC Fluent 验证规则,但由于某种原因,其中一个验证规则失败。添加了常规表达式...

回答 2 投票 0

在序列化中将长数字转换为字符串

我有一个使用 long 作为 ID 的定制类。但是,当我使用 ajax 调用我的操作时,我的 ID 被截断并且丢失了最后 2 个数字,因为 javascript 在处理...时会丢失精度。

回答 6 投票 0

如何通过 SignalR 从数据库获取总数

我想通过signalR获取员工总数 但我做不到 我在我的项目 asp core 上添加 signalR 创建中心 > 仪表板Hub ////////////////////////////////////////////////////////// 创建 dasjboard.js ////////////////////////////// 铬...

回答 1 投票 0

.NET 项目中缺少系统 DLL

我有一个由多个项目组成的 .NET 解决方案 - 其中大多数只是简单的 C# 库。其中之一是 MVC Web 应用程序。 每个项目的所有参考文献都缺少参考文献...

回答 4 投票 0

Application Insights 遥测显示私有负载均衡器后面的 MVC 4 应用程序为“NA”

您好 Stack Overflow 社区, 当我的 MVC 4 应用程序部署在私有负载均衡器后面时,我遇到了 Application Insights 遥测问题。在本地,CPU 和内存遥测...

回答 1 投票 0

在 AspNetRoles 表标识中添加新角色

如何在Identity中的AspNetRoles表中添加新角色? var roleresult = UserManager.AddToRole(currentUser.Id, "Admin"); 我正在使用上面的代码将管理员角色分配给用户,但它......

回答 2 投票 0

将 JSON 而不是模型从我的控制器传递到我的 Razor 视图

我有一个继承以下内容的视图: @model MvcApplication.Models.Application 但我需要知道是否可以以与传递模型对象相同的方式将 JSON 对象传递到我的视图...

回答 2 投票 0

如何在不使用模型的情况下使用.cshtml文件中的列表数据

这个问题可能非常基本,但我对 C# 非常陌生。我从控制器返回列表数据而不使用模型。我想使用它并想创建一个表。 // 我的控制器 ...

回答 3 投票 0

在同一页面内的选项卡之间共享相同的 ViewModel?

父部分视图使用包含 3 个子模型的 ViewModel。 @using MyDomain.ViewModel.EventViewModel 它有 5 个选项卡,如下所示: ... 父部分视图使用包含 3 个子模型的 ViewModel。 @using MyDomain.ViewModel.EventViewModel 它有以下 5 个选项卡: <div class="tab-pane active tabClass" id="tabs-1"> @Html.Partial("_tab1", Model) </div> <div class="tab-pane active tabClass" id="tabs-2"> @Html.Partial("_tab2", Model) </div> <div class="tab-pane active tabClass" id="tabs-3"> @Html.Partial("_tab3", Model) </div> <div class="tab-pane active tabClass" id="tabs-4"> @Html.Partial("_tab4", Model) </div> <div class="tab-pane active tabClass" id="tabs-5"> @Html.Partial("_tab5", Model) </div> 每个选项卡中有一个表单,用户需要填写并单击“下一步”以转到下一个选项卡。在最后一个选项卡上,他/她可以点击提交将所有内容(ViewModel)发送到控制器/操作并直接到另一个页面。 我的问题是,如果我以这种方式将模型传递到这 5 个部分视图中,是否会有 5 个不同的副本/实例,或者只有一个在它们之间共享?我问的原因是因为我担心每个选项卡都有自己的 ViewModel 实例,并且当在最后一个选项卡中点击提交按钮时,只有来自该选项卡的输入才会保存到模型中并提交(换句话说,来自tab1-4没有记录) 在您的场景中,ViewModel 的单个实例用于渲染部分视图。一旦页面被渲染,ViewModel 本身就不会保留。这只是一个 HTML 页面。 输入字段的名称属性与 ViewModel 的属性相匹配。提交表单后,数据将根据匹配的名称属性反序列化到您的 ViewModel 中。只要它们的名字正确,你就应该很好。 确保将所有输入(所有选项卡)放入一个表单中。

回答 1 投票 0

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