razor

Is there a way to use javaScript syntax inside Html helper

眉间皱痕 提交于 2020-01-06 04:19:50
问题 I have the following code inside my razor view:- @Html.PagedListPager(Model , page => Url.Action("Index","Server", new { searchTerm = ViewBag.searchTerm, page, sort = ViewBag.CurrentSortOrder, pagesize = $("#pagesize").val() }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast, new AjaxOptions { UpdateTargetId = "ServerTable" , LoadingElementId="progress2" })) But i am unable to get the value of field using the following $("#pagesize").val()

passing multiple parameters in @html.actionlink()

蹲街弑〆低调 提交于 2020-01-06 04:03:42
问题 I'm using actionlink to pass parameter "code" to controller for an item and get details for that item on new view (actually, it's controller that calls 3 partial views) I also need to pass parameter "description" but that's just an value that need to be shown as on new view and has no use in controller (i'm using "code" to filter database records). @foreach (var item in Model.MyModel) { <tr> <td> @Html.ActionLink(item.code, "Index", "ControlerName", new { pos = item.code.ToString(), desc =

Element naming convention in Razor generator within a foreach loop

孤街醉人 提交于 2020-01-06 03:56:26
问题 I'm trying to generate element names using Html.NameFor<> method, here's my code: @foreach (var category in Model.Categories) { <input type="hidden" name="@Html.NameFor(m=> category.CategoryId)" value="@category.CategoryId" /> } The generated item's name get this value: category.CategoryId , instead of Categories[i].CategoryId (where i refers to the current indexer). Why isn't it working? 回答1: in short, use a for loop instead of a foreach loop (see the answer here). You need to manually index

Html Helper with special htmlattributes

南楼画角 提交于 2020-01-06 03:48:04
问题 Does anyone know how to pass html attributes like "data-date" to the Html.TextBox()?? It is used from the bootstrap datepicker. Is there a way around it? @Html.TextBoxFor(p => p.DateFrom, new { @class = "small", type = "date", "data-date"="12-02-2012" }) 回答1: You have to use underscore instead of '-'. So what you're after would go something like this: @Html.TextBoxFor(p => p.DateFrom, new { @class = "small", @type = "date", @data_date="12-02-2012" }) 回答2: Use: new Dictionary<string, object> {

Selected radio button value not passing with postback data in MVC 5

♀尐吖头ヾ 提交于 2020-01-06 03:33:07
问题 I used Html.RadioButtonFor for item selection in list but it causes name attribute conflict. here is my sample model public class DataList { public List<Videos> { set; get;} } public class Videos { public int isSelected {set; get;} public int id {set; get;} public string Title { set; get;} --- } View template will look like this @for (var i = 0; i <= Model.DataList.Count - 1; i++) { <label class="radio">@Html.RadioButtonFor(m =>Model.Videos[i].isSelected, Model.Videos[i].id)</label> } But

How to bind a DataTable to a DropDownList using MVC RAZOR?

戏子无情 提交于 2020-01-06 03:06:30
问题 My Model returns a collection of DataTables as shown below. How to bind a DataTable to a DropDownList using MVC RAZOR? For each DataTable, I'd like to create a table row and a drop down list for it. I tried the below code: foreach (DataTable dataTable in Model.ParameterDataSources) { <tr> <th> Filter: </th> <td> @Html.DropDownList("ddlFilterDataSource", dataTable, "--Select One--") </td> </tr> } How to achieve this? 回答1: A Simple solution is to convert your DataTable to DataView, and you

Change syntax coloring for a file extension in Visual Studio 2013

让人想犯罪 __ 提交于 2020-01-06 02:41:32
问题 I have a file1.cshtml that really contains JSON data. I'd like the syntax highlighting, etc. to reflect this. I tried going to Tools > Options > Text Editor > File Extension and changed the cshtml extension's Editing Experience to be JSON Editor. I then closed and reopened Visual Studio, but my editor isn't showing the desired syntax highlighting. I can copy and paste the contents of file1.cshtml into file2.json and everything looks ok, but I'd rather not have to do it this way. I'm using

ASP.NET MVC3 HtmlHelper extension method like BeginForm that uses a partial view?

倾然丶 夕夏残阳落幕 提交于 2020-01-06 01:29:23
问题 I created an extension method based on this answer to the SO question c# - How can I create a Html Helper like Html.BeginForm - Stack Overflow and it works fine. Can I move the embedded HTML in the extension method into a partial view and use that partial view in the method while preserving it's current behavior? In particular, I want to be able to 'wrap' a block of arbitrary HTML. I ask not out of any pressing need, but simply out of a desire to maintain HTML consistently, e.g. as views and

Url.Action in jquery ajax: Second parameter not passed

安稳与你 提交于 2020-01-05 13:09:31
问题 I am trying to pass two parameters in an Url.Action function with jQuery ajax, and only the first parameter is passed. Both parameters show up correctly in the ajax function when I debug. The values passed in data are passed correctly. What am I doing wrong? Here is the code from the view: <script type="text/javascript"> $(function () { $("#sendForm").click(function () { //they both show correctly in the console console.log('@ViewData["recordURL"]'); console.log('@ViewData["title"]'); $.ajax(

MVC3 Razor “For” model - contents duplicated

▼魔方 西西 提交于 2020-01-05 12:31:55
问题 It has been intriguing that my MVC3 razor form renders duplicated values inside a foreach code block in spite of correctly receiving the data from the server. Here is my simple form in MVC3 Razor... -- sample of my .cshtml page @model List<Category> @using (@Html.BeginForm("Save", "Categories", FormMethod.Post)) { foreach (Category cat in Model) { <span>Test: @cat.CategoryName</span> <span>Actual: @Html.TextBoxFor(model => cat.CategoryName)</span> @Html.HiddenFor(model => cat.ID) <p>---</p> }