Tag: asp.net mvc

如何通过asp.net mvc c获取浏览网站的客户端的mac地址#

我正试图从浏览我的网站的客户端机器获取mac地址,我已经习惯了: using System.Management; class Sample_ManagementClass { public static int Main(string[] args) { ManagementClass objMC = new ManagementClass(“Win32_NetworkAdapterConfiguration”); ManagementObjectCollection objMOC = objMC.GetInstances(); foreach (ManagementObject objMO in objMOC) { if (!(bool)objMO[“ipEnabled”]) continue; Console.WriteLine((string)objMO[“MACAddress”]); } } } 但它无法识别管理命名空间,所以我该怎么办?

使用iTextSharp创建PDF时输入页码

我正在使用ASP MVC,我使用iTextSharp在我的应用程序中生成PDF。 但现在我有一个问题:我打印列表,当存在多个页面时,我想显示页码(例如: Page 1 to 4 )。 我找到了一些例子,但我认为它比我需要做的更复杂(比如exameple )。 编辑:我发现这个例子2 。 我可以计算页数,但我不能打印页数。 我做了什么: public ActionResult downloadListaISCC(DateTime? DataFimFiltro) { //Code to generate list to PDF //My document Document doc1 = new Document(); doc1.SetPageSize(iTextSharp.text.PageSize.A4); doc1.SetMargins(0f, 0f, 0f, 0f); doc1.NewPage(); MemoryStream pdfStream = new MemoryStream(); PdfWriter pdfWriter = PdfWriter.GetInstance(doc1, pdfStream); //Code to create table doc1.Add(table); //table list […]

如何在Asp.net MVC和entity framework中进行分页时应用filter?

我有一个使用ASP.NET MVC框架编写的Web应用程序。 在我的Homecontroller我有一个名为Index的动作,它响应Get请求。 在此操作中,我使用IPagedList库创建页面以将记录分成多个页面。 我的Index@HttpGet看起来像这样 public ActionResult Index(int? id) { using(var connection = new Context()) { int pageNumber = (id ?? 1); var presenter = new Presenter { Presenter = pageNumber, Tasks = connection.Tasks.ToPagedList(pageNumber, 30), Form = new TasksFiltersViewModel() } return View(presenter); } } 我还有一个名为Index的操作,它响应Post请求,该请求应用了一些filter。 所以在Post请求中我做了这样的事情 [HttpPost] [ValidateAntiForgeryToken] public ActionResult Index(Presenter model) { int pageNumber […]

使用远程validation进行多个字段validation

我有以下型号: public class Customer { public string FirstName {get;set;} public string LastName {get; set;} [Remote(“CardExisting”, “Validation”, AdditionalFields=”FirstName,LastName”) public string CardNumber {get; set;} } CardExisting操作将检查firstName和LastName的cardNumber组合是否存在现有记录。 如果用户首先输入卡号然后输入他的名字,我无法validation他怎么办?所以当他返回并输入他的名字时我需要再次进行远程validation,如果焦点已经从cardnumber属性丢失了怎么办呢?

mvc Html.BeginForm不同的URL架构

我正在为这样的DropDown创建一个表单: @{ Html.BeginForm(“View”, “Stations”, FormMethod.Get); } @Html.DropDownList(“id”, new SelectList(ViewBag.Stations, “Id”, “Name”), new { onchange = “this.form.submit();” }) @{ Html.EndForm(); } 如果我从我的下拉列表中选择一个值,我会被重定向到正确的控制器,但URL不是我想要的: /站/视图?ID = f2cecc62-7c8c-498d-b6b6-60d48a862c1c 我想要的是: /站/查看/ f2cecc62-7c8c-498d-b6b6-60d48a862c1c 那么如何将id = querystring参数替换为我想要的更简单的URL方案呢?

传递两个模型来查看

我是mvc的新手,并尝试用它做一个小项目来学习它。 我有一个页面应该显示特定日期的货币和天气。 所以我应该通过货币模型和天气模型。 我已经完成了传递货币模型并且工作正常,但我不知道如何通过第二个模型。 并且大多数教程都展示了如何只传递一个模型。 你们能不知道如何做到这一点。 这是我当前的控制器动作,它发送货币模型 public ActionResult Index(int year,int month,int day) { var model = from r in _db.Currencies where r.date == new DateTime(year,month,day) select r; return View(model); }

Azure ASP .net WebApp请求超时

我已经将ASP .net MVC Web应用程序部署到Azure App服务。 我从我的网站做一个GET请求到一些从DB(DbContext)获取数据的控制器方法。 有时,从数据库获取数据的过程可能需要4分钟以上。 这意味着我的请求没有超过4分钟的动作。 之后Azure杀死连接 – 我得到消息: 500 – 请求超时。 Web服务器无法在指定时间内响应。 这是一个方法示例: [HttpGet] public async Task LongGet(string testString) { var task = Task.Delay(360000); await task; return Json(“Woke”, JsonRequestBehavior.AllowGet); } 我见过很多这样的问题,但我没有回答: 不工作1不能给其他链接 – 声誉太低。 我已经阅读了这篇文章 – 它关于Azure负载均衡器,它不适用于webapps,但是它写的是在Azure webapp中处理我的问题的常用方法是使用TCP Keep-alive。 所以我改变了我的方法: [HttpGet] public async Task LongPost(string testString) { ServicePointManager.SetTcpKeepAlive(true, 1000, 5000); ServicePointManager.MaxServicePointIdleTime = […]

属性的客户端ID(ASP.Net MVC)

我是asp.net mvc的初学者,我有一个疑问: 我正在尝试在我的视图中为TextBox做一个标签,我想知道,我如何获取将在客户端渲染的Id以生成脚本…例如: <label for="”> Name: x.Name) %> 我需要在“ClientId”中放置什么来确保将正确的ID呈现给相应的控件? 谢谢 干杯

登录后如何更改路由到用户名?

在用户登录之前,路由是: localhost:54274/Home localhost:54274/Home/About localhost:54274/Home/Contact localhost:54274/Home/Login localhost:54274/Home/Register 用户登录后,路由为: 1. localhost:54274/Project 2. localhost:54274/Project/Create 3. localhost:54274/Project/Edit/1 4. localhost:54274/Project/Delete/2 5. localhost:54274/Project/1/Requirement 6. localhost:54274/Project/1/Requirement/Create 7. localhost:54274/Project/1/Requirement/Edit/3 8. localhost:54274/Project/1/Requirement/Delete/4 我想在用户登录后将路由更改为用户名。例如,用户名为hendyharf。 1. localhost:54274/hendyharf/Project 2. localhost:54274/hendyharf/Project/Create 3. localhost:54274/hendyharf/Project/Edit/1 4. localhost:54274/hendyharf/Project/Delete/2 5. localhost:54274/hendyharf/Project/1/Requirement 6. localhost:54274/hendyharf/Project/1/Requirement/Create 7. localhost:54274/hendyharf/Project/1/Requirement/Edit/3 8. localhost:54274/hendyharf/Project/1/Requirement/Delete/4 我的项目的控制器只有3个控制器: HomeController , ProjectController和RequirementController 我的RouteConfig.cs仍处于默认状态 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute( name: “Default”, […]

是否在Asp.net MVC中延期执行查看非常糟糕的事情?

假设我有通过entity framework获得的以下模型: public class User{ public string Name {get;set;} public int Id {get;set;} } 从用户表中获取所有用户: IEnumerable users = from u in myDbContext.Users select u; 在View中重新查看用户(@model IEnumerable): @foreach(var item in Model) { @item.Id @item.Name } 我的新老板告诉我,这样做是不符合MVC,性能会非常糟糕。 我应该做的是使用.ToList()将Controller中的所有USERS资格化。 我不确定什么是更好的,因为无论哪种方式用户必须实现,我没有看到任何性能损失。