Tag: 视图

如何使用CommandParameter传递UserControl?

我使用DelegateCommand,我想通过Command传递UserControl。 #region OpenViewCommand private DelegateCommand _openViewCommand; public ICommand OpenViewCommand { get { if (_openViewCommand == null) _openViewCommand = new DelegateCommand(new Action(OpenView)); return _openViewCommand; } } public void OpenView(UserControl ViewName) { UserControl ctrl = (UserControl)ViewName; JIMS.Controls.Message.Show(ViewName.ToString()); } #endregion XAML中的命令 stock group

如何在视图ASP MVC中使用模型数据?

我是ASP MVC的初学者,我正试图在视图中显示模型中的数据。 这是我显示数据的方式: @Html.DisplayFor(modelItem => item.Budget_Year) 但我不知道如何使用这些数据,例如我试图对这个结果进行舍入,我天真地尝试过: @{ double test = (modelItem => item.Budget_Year); test = System.Math.Round(test , 2); } 但我不能这样使用它: 无法将lambda表达式转换为’double’类型,因为它不是委托类型 在我看来,有人可以解释一下如何在我的模型中使用这些不同的项目吗? 最好的祝福, 亚历克斯

如何使用C#在SQL Server数据库中创建视图?

如何使用C#在SQL Server中动态创建视图?

具有键“Survey_Group”的ViewData项的类型为“System.String”,但必须是“IEnumerable ”类型

我已将db中的值绑定到下拉列表。 但是,当我尝试在视图中提交时,它显示: 具有键“Survey_Group”的ViewData项的类型为“System.String”,但必须是“IEnumerable”类型。 有人可以指导我吗? 谢谢。 模型: [MaxLength(100)] [DisplayName(“Owner Groups”)] public string Survey_Group { get; set; } 视图: @Html.LabelFor(model => model.Survey_Group, “Owner Groups”) @Html.DropDownListFor(model => model.Survey_Group, (SelectList)ViewBag.GroupList) 控制器: public ActionResult SURV_Main_Create() { ViewBag.CurrentPage = “create”; var model = new SURV_Main_Model(); ViewBag.GroupList = new SelectList(db.SURV_Group_Model, “Group_ID”, “GroupName”); return View(model); } // POST: /SURV_Main/Create [HttpPost] [ValidateAntiForgeryToken] public ActionResult […]

如何测试PARTIAL视图是在C#ASP .NET MVC中呈现的

我有一个视图,它内部有部分视图渲染: @Html.RenderPartial(“partial”, Model.SomeModelProperty); 还有一个控制器,它返回这个视图 public ActionResult Action() { … var model = new SomeModel(){SomeModelProperty = “SomeValue”} return View(“view”, model); } 如何测试视图呈现我知道: [TestMethod] public void TestView() { … var result = controller.Action(); // Assert result.AssertViewRendered().ForView(“view”).WithViewData(); } 但是当我打电话的时候 result.AssertPartialViewRendered().ForView(“partial”).WithViewData(); 我收到此错误消息 Expected result to be of type PartialViewResult. It is actually of type ViewResult. 我究竟做错了什么?

MVC ASP.NET中的ViewData和ViewModel

我是.Net开发的新手,现在正在关注NerdDinner教程。 只是想知道你们中是否有人能告诉我 ViewData和ViewModel之间有什么区别 (我所知道的是他们习惯将某些forms的数据从控制器传递到视图)并且可能告诉我应该在什么情况下使用ViewData而不是ViewModel,反之亦然 提前致谢! 出击

将多个结果集传递给ASP.NET MVC中的控制器的视图?

所以我有一个控制器设置如下: using NonStockSystem.Models; namespace NonStockSystem.Controllers { [Authorize(Users = “DOMAIN\\rburke”)] public class AdminController : Controller { private NonStockSystemDataContext db = new NonStockSystemDataContext(); public ActionResult Index() { var enumProducts = from p in db.Products select p; ViewData[“Title”] = “Administration”; return View(enumProducts.ToList()); } } } Admin控制器上的Index视图只列出系统中的产品,并允许我们单击产品以查看/编辑/删除它。 真的很简单。 但是,每个产品都有一个CategoryID,它告诉我们哪个类别存储在一个单独的表中。 (非常简化的)当前视图是这样的: (<a href="https://stackoverflow.com/Admin/Edit/”>Edit – <a href="https://stackoverflow.com/Admin/Delete/”>Delete) 目前这很好,因为系统中只有10或15个产品,而我开发和测试它然而,一旦我部署它将有大约。 数据库中有300个产品。 我很好地将它们全部显示在一个页面上但是我想使用(一个href =“#category”)链接很像维基百科这样做在页面顶部我可以有类别列表,当你点击一个它带你到页面的适当部分。 […]

在tabControls tabPage中更改和传递内容

我在Windows窗体应用程序中工作,并有以下问题。 我在我的应用程序中使用tabControl,当用户执行特定操作时,需要更改某些tabPages中的内容。 例如tabPage one包含一个文本区域和一个按钮,当用户点击文本区域内的按钮信息时应该以某种方式存储,并且相同的tabPage应该显示新的内容,例如更多的文本区域,按钮等,我认为它更容易通过使用其中的视图,可以隐藏一个视图,也可以显示另一个视图。

在MVC中将值从Controller传递给View

我有一个使用数据脚手架生成的视图。 该视图有一个文本字段: 创建视图: @Html.LabelFor(model => model.GroupId, htmlAttributes: new { @class = “control-label col-md-2” }) @Html.EditorFor(model => model.GroupId, new { htmlAttributes = new { @class = “form-control” } }) @Html.ValidationMessageFor(model => model.GroupId, “”, new { @class = “text-danger” }) 我想将控制器中的值传递给此文本字段。 我做了以下,似乎没有用。 控制器: public ActionResult Create(int id) { ViewBag.GroupId = id; Debug.WriteLine(“DEBUG: “+id); return View(); }

不允许子操作执行重定向操作。 (使用PartialViews)

我正在尝试使用数据库中的一些数据加载我的部分视图,但是当我运行应用程序时,我遇到了以下问题: 不允许子操作执行重定向操作。 我不知道为什么会这样,因为我对MVC技术很新。 这是控制器中的PartialViewResult方法: public PartialViewResult UnReadEmails() { if (User.Id != null) { List resultList = EmailController.GetUnreadEmailsByUserId(User.Id); return PartialView(“~/Views/Emails/_UnReadEmails.cshtml”, resultList); } return PartialView(“Error, not found!”); } 这是我的部分视图本身,它被称为_UnReadEmails(你可以看到我在这里显示有关发件人和电子邮件正文的信息),PartialView正在检索我从我的控制器发送的电子邮件列表 @model IEnumerable foreach (var item in Model) { @item.EmailSender @item.Body; } 在我尝试以这种方式加载我的局部视图后: @Html.Action(“UnreadEmails”, “Message”) 我开始收到我在标题中提到的以下问题, 我已经尝试过几件事来解决这个问题,例如将@Html.Action(“UnreadEmails”, “Message”)更改为@Url.Action(“UnreadEmails”, “Message”)等等,但这并没有解决我的问题。 编辑:它总是打破这一行(在视图上): @Html.Action(“UnreadEmails”, “Message”) 它永远不会进入代码背后.. 在Chris建议之后,我在方法的顶部添加了[AllowAnonymous] : [AllowAnonymous] public PartialViewResult UnReadEmails() […]