Tag: razor

MvcRazorToPdf – 图像无法渲染,MVC4

我一直试图渲染图像,但没有积极的结果。 是否需要添加任何具体内容才能使其正常工作。 我不包括渲染的其余部分,但在pdf中,图像丢失了。 我按照以下链接: https://github.com/andyhutch77/MvcRazorToPdf 视图 @model Test.Models.PdfExample @{ ViewBag.Title = “Index”; Layout = “~/Views/Shared/_Layout.cshtml”; var imagePath = Server.MapPath(“~/Content/Images”); } // not rendering @**@ 我可以看到 占据width and height但它没有显示其内部的图像。

处理回发数据中的数组 – MVC3

我现在是一个试图转向MVC的WebForms开发人员。 我对MVC非常兴奋,我真的很开心,但我遇到了一个奇怪的问题。 所以我要做的是为“小部件”创建一个高级编辑器。 我已经发布了以下代码。 添加前4-5项时,一切似乎都能正常工作,但删除第二项时会出现问题。 这是一个视觉示例。 首先添加4个值。 但是当我们删除第二个值时会出现问题。 我们最终得到了…… 我似乎无法理解的是,为什么此属性在以下两行代码之间有所不同。 @Model.Values[i] @Html.TextBoxFor(m => m.Values[i]) 我的猜测是@Model和(m => m)不引用同一个对象? 这是我的小部件类。 public class Widget { #region Constructor public Widget() { ID = 0; Name = string.Empty; Values = new List(); } #endregion #region Properties [Required] [Display(Name = “ID”)] public int ID { get; set; } [Required] [Display(Name = […]

从另一个控制器查看字符串

我已经完成了Vdex建议: https ://stackoverflow.com/a/5801502/973485并使用他找到的RenderPartialToString方法。 它完美地工作如下: public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult Test() { string t = ViewToString.RenderPartialToString(“Index”, null, ControllerContext); return Content(t); } } 但如果我想从另一个Controller渲染Home> Index,我得到: Value cannot be null. Parameter name: controllerContext 像这样: public class FooController : Controller { public ActionResult Index() { string t = ViewToString.RenderPartialToString(“Index”, […]

使用Ajax和iframe下载文件

我读过有关使用Ajax和iframe进行文件下载的文章。 任何人都可以给我一步一步解释如何执行此操作或知道任何教程,因为我们已经在此项目上使用ajax这似乎是最好的方法。 编辑: 好的,这是我的查看代码: $(function () { $(‘#downloadfile’).click(function (e) { $(‘#downloadIframe’).attr(‘src’, ‘@Url.Action(“DownloadFile”,”Invoice”)’ + ‘/Report/Invoices’); }); }); 这是我的控制器: public FileResult DownloadFile(int id) { byte[] fileBytes = System.IO.File.ReadAllBytes(Server.MapPath(“~/Reports/Invoices/” + Table.First(x => x.ID == id).ID + “.pdf”)); string fileName = Table.First(x => x.ID == id).ID.ToString(); return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Pdf, fileName); } public ActionResult Download(int id) { return AjaxResponse(“Download”, null); […]

MVC5 Autofac:找不到的视图

我创建了非常简单的MVC 5.0应用程序,我推送到GitHub存储库: https : //github.com/marxin/mvc-sample 。 我的动机是使用mono 3.2.3在Linux上执行app。 我想添加Autofac NuGet包(更确切地说是3.3.0),这对我来说很好。 问题是,如果我添加Autofac.Mvc5集成包,Razor将停止处理以下错误: System.InvalidOperationException The view found at ‘~/Views/Home/Index.cshtml’ was not created. Description: HTTP 500.Error processing request. Details: Non-web exception. Exception origin (name of application or object): System.Web.Mvc. Exception stack trace: at System.Web.Mvc.BuildManagerCompiledView.Render (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) [0x00000] in :0 at System.Web.Mvc.ViewResultBase.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x00000] in :0 […]

MVC4:使用chrome将.xlsx文件导出为mvc。 它适用于.xls但不适用于.xlsx

如何使用chrome通过mvc将.xlsx文件导出为ex​​cel。 它适用于.xls但不适用于.xlsx Response.ClearContent(); Response.AddHeader(“content-disposition”, “attachment; filename= Estimate1.xlsx”); Response.ContentType = “application/excel”; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); Response.Write(sw.ToString()); Response.End(); 当我打开excel文件。 它表现得像这样。 “Excel无法打开文件’FileName.xlsx’,因为文件格式或文件扩展名无效。” 非常感谢你的帮助! 🙂

如何解决ASP.NET MVC Kendo UI网格中的CRUD操作问题

我一直在努力让Kendo UI网格充当我正在编写的系统中的用户管理工具。 我已将数据绑定到网格,使用ASP.NET Identity获取用户信息,但我似乎无法获取更新或删除操作以触发网格。 我把网格设置如下: @(Html.Kendo().Grid() .Name(“userGrid”) .Columns(columns => { columns.Bound(p => p.UserName); columns.Bound(p => p.FirstName); columns.Bound(p => p.LastName); columns.Bound(p => p.Region); columns.Bound(p => p.Roles); columns.Command(command => { command.Edit(); command.Destroy(); command.Custom(“ViewDetails”).Click(“showDetails”); }); }) .Filterable() .Sortable() .Navigatable() .Resizable(r => r.Columns(true)) .Editable(editable => { editable.Mode(GridEditMode.InLine); editable.DisplayDeleteConfirmation(“Are you sure you want to delete this user?”); }) .HtmlAttributes(new { […]

尽管提交按钮,Html.BeginForm仍未发布到服务器

我有一个标准的表单,它被包装成一个Html.BeginForm。 在底部有一个提交按钮。 但是,当点击按钮时,我的控制器没有被击中。 我遇到了页面的重新加载,但没有遇到任何代码。 我试图在控制器端进行调试并尝试我能看到的代码被击中,但它的定义并没有被击中。 Razor – /Views/BuyBitcoins/Index.cshtml下的Index.cshtml: @using (Html.BeginForm(“BuyBitcoinsNow”, “BuyBitcoins”,FormMethod.Post)) { @ModelRes.BuyBitcoinStrings.Form_YourPurchase @ModelRes.BuyBitcoinStrings.Form_HowMuch @Html.EditorFor(model => model.PurchaseViewModel.PurchaseAmount) @ModelRes.BuyBitcoinStrings.Form_EnterAddress @Html.EditorFor(model => model.PurchaseViewModel.BitcoinAddress) @ModelRes.BuyBitcoinStrings.Form_Summary @ModelRes.BuyBitcoinStrings.Form_Personal_Headline @ModelRes.BuyBitcoinStrings.Form_Name: @Html.EditorFor(model => model.Name) @ModelRes.BuyBitcoinStrings.Form_Email: @Html.EditorFor(model => model.Email) @ModelRes.BuyBitcoinStrings.Form_Phone @Html.EditorFor(model => model.Phone) @ModelRes.BuyBitcoinStrings.Form_accept @ModelRes.BuyBitcoinStrings.Form_newsletter @ModelRes.BuyBitcoinStrings.Form_usp1 @ModelRes.BuyBitcoinStrings.Form_usp2 @ModelRes.BuyBitcoinStrings.Form_usp3 } RouteConfig.cs: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute( name: “Order info”, url: “orders/{id}”, […]

在剃刀视图中设置分页页面大小DropDownList

我想在我的asp.net网页表单页面大小选择下拉列表。 实际上我已经做到了,但是当我从下拉列表中更改页面大小时,没有任何改变。 我想我需要在我的控制器中写一些额外的东西,或者我的View可能是错的? 我的Index.cshtml视图: @model TimeReportingWebApp.TimeReportViewMod @using PagedList.Mvc; …. @using (Html.BeginForm(“Index”, “Users”)) { Find by name: @Html.TextBox(“SearchString”, ViewBag.CurrentFilter as string) } @Html.ActionLink(“Login”,”Index”, new { sortOrder = ViewBag.LoginSortParm, currentFilter = ViewBag.CurrentFilter }) @foreach (var item in Model.Model2) { @Html.DisplayFor(modelItem => item.Login) } Page @(Model.Model2.PageCount Url.Action(“Index”, new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }) ) […]

POST到MVC控制器当我没有按顺序选中复选框时,IEnumerable嵌套模型为null

当我试图在Post中获取值时,当我不按顺序(1,2,3等)检查时,复选框的值被设置为NULL。 我需要选择任何顺序(即4,5)。 模型: public class AssignUsersViewModel { [Display(Name = “Check to select”)] public bool Select { get; set; } public int Id { get; set; } [Display(Name = “App. Username”)] public string UserName { get; set; } [Required] public string GivenName { get; set; } [Required] public string Surname { get; set; } [Display(Name = […]