razor

Display partial view in a view using mvc 4

让人想犯罪 __ 提交于 2020-01-24 12:47:05
问题 I want to display a partial view inside a main view upon clicking view link, within the same page. Help me please, I am newbie in MVC. Is there any other way to do it other than using the Ajax.ActionLink()? This is my Add Detail controller. public ActionResult DisplayDetails() { SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString()); connect.Open(); DataSet ds = ExecuteQuery("select EmployeeID, EmployeeName, EmailID from EmployeeDetails");

Using EditorFor in Foreach or For loop (ASP.NET MVC + RAZOR)

为君一笑 提交于 2020-01-24 10:49:46
问题 I'm currently implementing a Family Tree system in my ASP.NET MVC project. In order to set the relationship between family members, I need to display two ComboBox/DropDownList per row to define relationships from one member to the other. First I will share my codes and then I will explain what ways I've tried so far and what was the result at the end. ViewModel public class FamilyTreeRelationshipViewModel { [ScaffoldColumn(false)] public string FromMemberId { get; set; } [ScaffoldColumn(false

MVC 3 model foreach filter

不羁岁月 提交于 2020-01-24 10:34:08
问题 I have the following razor syntax @{ foreach (var p in Model) { <b>@p.Age</b> } } I would like to filter the foreach loop to only look at the Model records where p.City = "New York" What would my syntax look like ? I hope that I am explaing this right. Thanks 回答1: @foreach (var p in Model.Where(i => i.City == "New York")) { <b>@p.Age</b> } You might decide to do this filtering in the controller action, depending on whether you need other model records that don't have a city of "New York" in

Performance considerations with nested declarative @helpers in Razor

余生长醉 提交于 2020-01-24 10:06:29
问题 @helpers, along with partial views allow for great composability, however I would like to know if there is a significant performance cost to be aware. For example: App_Code\Wrappers.cshtml: @helper HeaderWrapper(WebViewPage view, Func<object, HelperResult> content,Func<object, HelperResult> navbar = null) { <div class="container-fluid"> @content(null) </div> if (navbar != null) { <div class="container-fluid"> <nav id="navbar-page" class="navbar-default navbar-collapse collapse" role=

Input with date format set from ViewModel and html class attribute

淺唱寂寞╮ 提交于 2020-01-24 04:52:10
问题 I am working with razor view engine in asp.net mvc3. Now, I need an input for a DateTime which should display the value in a fixed format (say dd-MMM-yyyy ). So I can do: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-MMM-yyyy}")] public DateTime StartDate { get; set; } And in the view: @Html.EditorFor(model => model.StartDate) But I need to add a class in the input. Which I think is not possible in EditorFor . So I could use @Html.TextBoxFor(model => model.StartDate,

how to write extension method for paging in mvc

拥有回忆 提交于 2020-01-24 04:14:05
问题 i've define static class to enable paging : public static class Pager { public static IEnumerable<T> PageData<T>(this IEnumerable<T> source, int currentPage, int pageSize) { var sourceCopy = source.ToList(); if (sourceCopy.Count() < pageSize) { return sourceCopy; } return sourceCopy.Skip((currentPage - 1) * pageSize).Take(pageSize); } } and i want in my controller to do like : var pagedDataCourses = products.OrderBy(p => p.productName).PageData(currentPage, pageSize); so where i can put that

Umbraco MVC Implementation - View does not depend on Umbraco implementations

痞子三分冷 提交于 2020-01-24 01:25:11
问题 I have followed this nice tutorial which explains how you can take even more advantage of using Umbraco as a content delivery system. Tutorial MVC Umbraco => Your model and views should not depend on specific Umbraco implementations which is a huge advantage for real front-end developers. The controller inherited from Umbraco.Web.Mvc.RenderMvcController in order to access the data from the CMS. Now my problem is that we can't use @HTML.actionlink for navigation, it seems that this is only

How to load JSON data into SlickGrid with Razor MVC-4

跟風遠走 提交于 2020-01-23 17:53:05
问题 I am new to jquery, slick grid and razor. I have gone through SlickGrid examples and am able to load static data into a SlickGrid. Now I am trying to load JSON data from MSSQL into my SlickGrid. I have seen a few examples online, but I believe I am missing something not mentioned in those examples. Here is what I have code. SlickGridProducts.js var grid; var columns = [ { id: "ProductID", name: "ProductID", field: "ProductID", width: 50 }, { id: "ItemDesc", name: "ItemDesc", field: "ItemDesc"

How to combine two view models in razor MVC asp.net

孤街浪徒 提交于 2020-01-23 10:10:08
问题 Lets say I have some models as follows: public class Model1 { public int ID{get;set;} public string Name{get;set;} } public class Model2 { public int ID{get;set;} public string Name{get;set;} } class CommonViewModel { public string Title{get;set;} public Model1 model1; public Model2 model2; } and I have a razor view as follows @model ProjectName.CommonViewModel @Html.LabelFor(m => model.Title) @Html.EditorFor(m => model.Title) @Html.LabelFor(m => model.model1.Name) @Html.EditorFor(m => model

Blazor - Web Components - WebAssembly - Micro frontends

坚强是说给别人听的谎言 提交于 2020-01-23 08:35:09
问题 I'm investigating about Micro Front Ends and being able to have features built in different technologies. So far, creating Web Components and using those on the Monolith is the best approach I have found. Looking into different ways on creating Web Components and serving the modules in different services has being a fun experience. Looking into WebAssembly with Blazor, I got a question: Can you create and host on a server a Web Component wrap in a Web Assembly? I try enable CORS and just