razor-2

How to bind HTML Drop Down List in MVC Razor view

邮差的信 提交于 2019-12-25 09:08:02
问题 in my project i'm getting IEnumerable collection, now want to bind this my Html Drop Down list my razor view code is as: @if (Model.LanguageNavigationLinkItem != null) { // drop down list item Collection var ddlItem = Model.LanguageNavigationLinkItem; @Html.DropDownList(ddlItem.ToList(),"-- Select Item --") } i couldn't bind this collection with my drop down list please any one help me. 回答1: Here is an example to bind dropdown using ViewBag . You can also use model to bind dropdown in similar

Get textbox value for Ajax ActionLink in MVC 4 / Razor

﹥>﹥吖頭↗ 提交于 2019-12-24 01:40:47
问题 I am doing a classic search field with a button. I am using Ajax.ActionLink for the button, and I cannot figure out how to get the textbox value posted in the ActionLink. I looks like this: <div class="input-append"> <input type="text" id="Company_CompanyName" /> @Ajax.ActionLink("search", "CompanySearch", new { searchString = "???" }, new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "CompanySearchResults" }, htmlAttributes: new { @class = "btn" })

RazorEngine extension method fails with RuntimeBinderException after upgrade to Razor 2/ RE 3.2

牧云@^-^@ 提交于 2019-12-22 21:42:44
问题 I have a RazorEngine project that fails following an upgrade to Razor 2.0 and RazorEngine 3.2.0 This worked fine in the previous Razor 1.0 based version of RazorEngine (3.0.8). I have an instance ( myInstance ) of a class ( MyClass ) and and extension method: namespace MyCompany.Extensions { public static class MyClassExtensions { public static string ExtensionMethod(this MyClass thing) { // do stuff } } } I want to call this in a RazorEngine view (simplified example, there are loads of these

MVC4 localization. Accessing resx from view

随声附和 提交于 2019-12-18 12:24:45
问题 In my view I would like to access resource strings from the specific local resource on that file.. Just as you know it from web-forms: (string)GetLocalResource("Title"); Painless and smooth. The framework handles which .resx file to get from the culture info code extension (.en-EN.resx). Is that possible in MVC4 with Razore view? And how? Iv'e noticed that i can set the Custom Tool property on the .resx file to PublicResXFileCodeGenerator . That way I can access it from the view. Example: I

MVC4 Ajax.BeginForm not replacing UpdateTargetId

核能气质少年 提交于 2019-12-18 12:18:01
问题 There are so many topics on SO about issues with the Ajax.BeginForm not correctly updating the target element with the return partial view: mvc4 ajax updating same page ASP.NET MVC 4 - Ajax.BeginForm and html5 MVC 4 (razor) - Controller is returning a partialview but entire page is being updated MVC 4 Ajax is not updating the PartialView within the page However, all of these are answered by either manually writing out the jQuery ajax, or including a missing javascript file. @using (Ajax

C# syntax to initialize custom class/objects through constructor params in array?

五迷三道 提交于 2019-12-18 05:38:45
问题 I have a class with minimum 4 variables and I have made a constructor for the class so that I can initialize it with MyClass testobj = new MyClass(1234,56789,"test text", "something else", "foo"); Works fine. Then I have an array of these, that I need to parse in a loop, so I would like to get some static data into this array. My approach was: MyClass[] testobjlist = new MyClass { new MyClass(1001,1234,"Text 1", "abcdefghijklm", "ding"), new MyClass(1002,2345,"Text xx", "bla bla", "dong"),

C# syntax to initialize custom class/objects through constructor params in array?

会有一股神秘感。 提交于 2019-12-18 05:38:04
问题 I have a class with minimum 4 variables and I have made a constructor for the class so that I can initialize it with MyClass testobj = new MyClass(1234,56789,"test text", "something else", "foo"); Works fine. Then I have an array of these, that I need to parse in a loop, so I would like to get some static data into this array. My approach was: MyClass[] testobjlist = new MyClass { new MyClass(1001,1234,"Text 1", "abcdefghijklm", "ding"), new MyClass(1002,2345,"Text xx", "bla bla", "dong"),

What is the syntax for a strongly-typed ActionLink in MVC 4 with MVC 4 Futures?

只愿长相守 提交于 2019-12-18 03:58:42
问题 I am using a new MVC 4 Internet application template with Visual Studio 2012. I have installed the Nuget package for MVC 4 Futures. In my _Layout.cshtml I am building the navigation menu. This works and builds the correct URL: @Html.ActionLink("Customers", "Index", "Customers") This is what I would like to work, a strongly-typed variation: @Html.ActionLink<CustomersController>(c => c.Index(), "Customers", null) It griefs on "Cannot choose method from method group. Did you mean to invoke a

Correct way to show an image that comes from a controller

纵饮孤独 提交于 2019-12-14 04:22:07
问题 I have a controller that loads an image file: // // GET: /MyController/Image/id public ActionResult Image(string id) { var dir = @"C:\Temp\Images"; var path = Path.Combine(dir, id + ".png"); return File(path, "image/png"); } In a separate view from action MyController/Page/id I have hastily hashed up some html to show the image: <img src="../image/@Model.Name" /> And then also with a link: <a href="../image/@Model.Name"> <img src="../image/@Model.Name" /> </a> It works, but I am looking for a

@Url.Content doesnt resolve absolute path on one server but does on another

对着背影说爱祢 提交于 2019-12-13 00:37:45
问题 We currently have two different servers on same domain. But one server resolves @Url.Content("~/api/User")' as http://domain.com/virtualdirectory/api/User where as other server doesnt resolve it absolutely; rather it resolves it relatively like api/user The code base is same and we are using MVC4. I am not sure as to where we went wrong or if there is any IIS/DNS settings that need to be done in order to get this fixed. All help is appreciated; thanks :) 回答1: This is related with the IIS