asp.net-mvc-2

Get object out of List< Tuple < object1, object2 > > and store in ViewModel

廉价感情. 提交于 2019-12-01 13:09:09
问题 [Suggestion: Want to read the answers in a logical manner ?? >> choose TAB [Oldest] Goal: Presentation of books with related inventorydetails on homepage such as Book.Title, InventoryDetail.Quantity etc. (Join|Book.BookId <=< InventoryDetail.BookId) Problem 1: How to join Problem 2: How to use a tuple (list of tuples) Problem 3: How to store the separated objects (from the list of tuples) into a Strongly Typed ViewModel Answer 1: An possible approach using Mike Brind's Guidance Answer 2:

conditional either or validation in asp.net mvc2

瘦欲@ 提交于 2019-12-01 12:48:23
In my registration page I have land line phone number and mobile number fields. I need to ensure that the user needs to add at least one phone number either the land line or mobile. How do I do this? Thanks Arnab You could write a custom validation attribute and decorate your model with it: [AttributeUsage(AttributeTargets.Class)] public class AtLeastOnePhoneAttribute: ValidationAttribute { public override bool IsValid(object value) { var model = value as SomeViewModel; if (model != null) { return !string.IsNullOrEmpty(model.Phone1) || !string.IsNullOrEmpty(model.Phone2); } return false; } }

Issue with AJAX Upload Script in mvc

最后都变了- 提交于 2019-12-01 12:32:47
问题 I found this ajax file upload script here http://www.phpletter.com/Demo/AjaxFileUpload-Demo/ Which is supposed to add ajax functionality to my file upload form <div id="dialog" title="Upload Image"> <% Html.BeginForm("Upload", "BugTracker", FormMethod.Post,new { id="uploadForm", enctype = "multipart/form-data"}); %> Select a file: <input type="file" name="file" id="file" /> <h6>Upload a screenshot related to the ticket</h6> <input type="submit" class="button" value="Upload" id="upload"

MVC CORE 2.0.0 run c# code on every page

孤者浪人 提交于 2019-12-01 12:03:30
问题 I need to run some c# code each time any page based on _layout.cshtml is viewed. I don't want to put something in every controller.cs file, just something central like you used to have in ASP.NET's MasterPage.cs Can't get this Run a method in each request in MVC, C#? or this @Html.Action in Asp.Net Core to run, not sure if it's because they're not CORE 2.0.0, I just get a lot of compilation errors. All I want to do is be able to run some code like this public class myClass { public static

jQuery Modal Window to Display a Table in MVC

為{幸葍}努か 提交于 2019-12-01 12:01:49
问题 Let me start of by saying that I am inexperienced with JavaScript. Here is what I want to do. When the user clicks "Show Details" on a row of data, they get a pop-up (modal?) window that has some data generated from another action within the MVC application. Where can I find an example of implementing something like this? Also, when a user clicks "Approve" on either this pop-up or on the original data row another pop-up will display with a form a person needs to fill out. Any direction will

sortable telerik grid + NHibernate, IQueryable and ASP.NET MVC

懵懂的女人 提交于 2019-12-01 12:00:22
问题 I am trying to get a telerik grid to work (paging works fine). My view code looks like this: @(Html.Telerik().Grid(Model) .Name("Grid") .Columns(columns => { columns.Bound(o => o.ItemName.Text).Title("Name"); }) .Pageable(pager => pager.PageSize(20)) .Sortable() ) My controller looks like this: public ActionResult Index(GridCommand command) { return View(BlaRepository.GetBlas(command.PageSize, command.Page)); } The repository looks like this: public IQueryable<Bla> GetBlas(int PageSize, int

ASP.NET MVC 2 RC2 Routing - How to clear low-level values when using ActionLink to refer to a higher level?

為{幸葍}努か 提交于 2019-12-01 11:16:33
[NOTE: I'm using ASP.NET MVC2 RC2.] I have URLs like this: /customers/123/orders/456/items/index /customers/123/orders/456/items/789/edit My routing table lists the most-specific routes first, so I've got: // customers/123/orders/456/items/789/edit routes.MapRoute( "item", // Route name "customers/{customerId}/orders/{orderId}/items/{itemId}/{action}", // URL with parameters new { controller = "Items", action = "Details" }, // Parameter defaults new { customerId = @"\d+", orderId = @"\d+", itemId = @"\d+" } // Constraints ); // customers/123/orders/456/items/index routes.MapRoute( "items", //

Too many JavaScript and CSS files on my ASP.NET MVC 2 Master Page?

為{幸葍}努か 提交于 2019-12-01 11:02:15
I'm using an EditorTemplate DateTime.ascx in my ASP.NET MVC 2 project. <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime>" %> <%: Html.TextBox(String.Empty, Model.ToString("M/dd/yyyy h:mm tt")) %> <script type="text/javascript"> $(function () { $('#<%: ViewData.TemplateInfo.GetFullHtmlFieldId(String.Empty) %>').AnyTime_picker({ format: "%c/%d/%Y %l:%i %p" }); }); </script> This uses the Any+Time™ JavaScript library for jQuery by Andrew M. Andrews III. I've added those library files ( anytimec.js and anytimec.css ) to the <head> section of my master page. Rather than

ASP.NET MVC - How can I set the Default Value in a Strongly Typed TextArea?

[亡魂溺海] 提交于 2019-12-01 10:42:56
I'm trying to make a TextArea have a default value. <%: Html.TextAreaFor(Function(model) model.Description, 5, 10, New With {.Value = "Description: "})%> This works properly in a TextBoxFor but doesn't work in a TextAreaFor Am I missing something very obvious? You can specify the value for Description property in the controller action when creating the model, and pass that model to the View: public ViewResult Create() { var model = new MyPageModel() { Description = "Description: "; } return View(model); } In the view: <%: Html.TextAreaFor(model.Description) %> Setting the value won't work as

ASP.NET MVC - How can I set the Default Value in a Strongly Typed TextArea?

冷暖自知 提交于 2019-12-01 09:09:31
问题 I'm trying to make a TextArea have a default value. <%: Html.TextAreaFor(Function(model) model.Description, 5, 10, New With {.Value = "Description: "})%> This works properly in a TextBoxFor but doesn't work in a TextAreaFor Am I missing something very obvious? 回答1: You can specify the value for Description property in the controller action when creating the model, and pass that model to the View: public ViewResult Create() { var model = new MyPageModel() { Description = "Description: "; }