razor

MVC4 Razor confused about braces

好久不见. 提交于 2019-12-18 20:05:10
问题 I've got a fairly simple question for all the Razor experts out there. I'm trying to make a jQuery $.ajax() call to a URL, using Url.Content() to translate the home-relative path into an root-relative path. In so doing, Razor is getting a bit confused about where the end of my @section is located. I'd prefer to be able to specify the URL inline, but when I do that, Razor thinks that the end of the $.ajax() parameter list is the end of my @section. I'm using @section because I want to use

MVC3 doesn't recognize MvcContrib namespace in Razor View

北慕城南 提交于 2019-12-18 19:28:24
问题 I'm trying to paginate something with MvcContrib's Html.Pager() , but my razor views can't reference the right namespace. Controller is ok: using MvcContrib.Pagination; ... public ActionResult List(int? page) { return View(new UserRepository().GetUserList().AsPagination(page ?? 1, 10)); } But, the view can't make sense of either: @using MvcContrib OR @Html.Pager((IPagination)Model) I installed MvcContrib via NuGet. I tried adding MvcContrib , MvcContrib.UI and MvcContrib.UI.Html namespaces to

what is the difference between ViewData & PageData in asp.net MVC 3?

我与影子孤独终老i 提交于 2019-12-18 19:13:10
问题 Well i see this 2 properties but i cant understand the difference between them? I cant seem to find any help anywhere about the PageData propriety. so can any body help? @ { Viewdata["something"] = 1; PageData["something"] = 2; } thanks 回答1: PageData is a property of WebPages that Razor is built on [it] Provides array-like access to page data that is shared between pages, layout pages, and partial pages. http://msdn.microsoft.com/en-us/library/system.web.webpages.webpagebase.pagedata(v=VS.99)

Why do we use HTML helper in ASP.NET MVC?

你。 提交于 2019-12-18 19:05:35
问题 Are there any good thing, best practice or profit we have after using the HTML helper in an ASP.NET MVC project? When I am trying to use them I found that I lose the speed I have with HTML and many difficulties I have whenever I use an HTML helper. Other [non-techie] persons can't understand what I write using Helper if I want to show them or they want to do something they need to spent more time on, even if they have working knowledge of HTML. If I use an HTML helper I lose the speed. When I

Why do we use HTML helper in ASP.NET MVC?

让人想犯罪 __ 提交于 2019-12-18 19:05:05
问题 Are there any good thing, best practice or profit we have after using the HTML helper in an ASP.NET MVC project? When I am trying to use them I found that I lose the speed I have with HTML and many difficulties I have whenever I use an HTML helper. Other [non-techie] persons can't understand what I write using Helper if I want to show them or they want to do something they need to spent more time on, even if they have working knowledge of HTML. If I use an HTML helper I lose the speed. When I

How can I create a SelectList with multiple selected values?

旧城冷巷雨未停 提交于 2019-12-18 18:54:21
问题 I'm trying to set multiple values in a select list: SelectList List = new SelectList(MyListItems, "valField", "dataField", <selected values>); What object/values do I use for to select multiple items? 回答1: You want to use MultiSelectList instead which has a constructor to meet your needs: public MultiSelectList( IEnumerable items, string dataValueField, string dataTextField, IEnumerable selectedValues ) 回答2: Example: class Person { int Id{ get; set; } string Name { get; set; } } ... var

Calling View of different folder from Asp.net mvc4 controller

最后都变了- 提交于 2019-12-18 18:53:53
问题 I hava a View Name "Message" in the Jobs folder of Views. And I want to return that view form an action of different controller, named "MarketController" public class MarketController : Controller { [HttpPost] public ActionResult Save() { // logic to save the record TempData["message"] = "Save successfully"; return View("Message"); } } The problem is that the "Message" view is not in the View of Market, how can i return that view from MarketController. (I do not want to use RedirectToaction

How to properly encode links to external URL in MVC Razor

巧了我就是萌 提交于 2019-12-18 18:53:45
问题 This view suppose to show a list of hyperlinks, each pointing to an external URL. The goal is for the user to click one of these links and have their browser open a new tab with the selected URL. Currently I have the following markup: @Html.ActionLink("SomeSite", "http://subdomain.mydomain.com/SomeSite") This markup produces: http://localhost:58980/AccessInstance/http%3a/subdomain.mydomain.com/SomeSite instead of : http://subdomain.mydomain.com/SomeSite What can I change in my markup to make

Is ASP.NET MVC 3 ready for business applications

拈花ヽ惹草 提交于 2019-12-18 18:51:48
问题 I have to decide about a new big business application we will develop in the coming years, the question is if we should start using MVC 3 or web forms. This was discussed already here in SO but I have seen the question: ASP.NET MVC ready for business applications (integrating 3rd party controls/components)? was asked in 2008 and now many things could have changed. My main concern is having heard MVC is good for rendering content like grids or lists and not so good for data input and user

@RenderSection in nested razor templates

霸气de小男生 提交于 2019-12-18 18:36:17
问题 My problem is I can't seem to use @RenderSection from a nested template when @RenderSection is defined in the base template. Currently, I have a nested base template which is linked to a child template which is then used in the view pages. When I define the @RenderSection in the base template and render it in the view pages it throws an error. Here's the exact problem. I want to create a RenderSection to allow me to insert custom scripts. My base template.... <!DOCTYPE html> <html> <head>