razor

How to convert date time format in a Razor view? [duplicate]

烂漫一生 提交于 2019-12-25 07:37:19
问题 This question already has answers here : Converting DateTime format using razor (9 answers) Closed 3 years ago . I need to display a date time string in the following format in a Razor view: 24 Jun'16 how can I convert the string in a Razor view? 回答1: Just like you normally would: @Model.YourDateTime.ToString("d MMM \\'yy") The \\ escapes the ' , since that is a preserved character. The rest is quite straightforward. Another option is the use of display attributes with DisplayFor :

Servicestack with Razor not working -> FORBIDDEN ressource

让人想犯罪 __ 提交于 2019-12-25 07:25:54
问题 I'm loosing my mind ... wanna use SS Razor feature in an empty web application on my Win 8.1 machine. Installed via NuGet, added a webpage at the root and get this error: >Forbidden >Request.HttpMethod: GET >Request.PathInfo: /default.cshtml >Request.QueryString: >Request.RawUrl: /default.cshtml >App.DebugLastHandlerArgs: >GET|/default.cshtml|Z:\GIT\MasterThesis\src\AppBlue\AppBlue.Web\default.cshtml I also tried the Razor rockstars sample app from SS - this works perfectly. So I've copied

Pass dropbox value to a HttpGet action submit button click?

纵然是瞬间 提交于 2019-12-25 06:57:21
问题 Basically I'm trying to pass the value of my dropbox to a get action. The submit-button re-directs to the correct action , but what is the correct way to add the value of the dropbox with the re-direction? My view: @model TrackerModel @using (Html.BeginForm("MyAction", "MyController", FormMethod.Get, new { ???})) { <div> <strong>@Html.LabelFor(m => m.CustomerName)</strong> @Html.TextBoxFor(m => m.CustomerName, new { type = "hidden", @class = "customer-picker" }) </div> <button class=

create a accessible dialog box for the error mesage

拥有回忆 提交于 2019-12-25 06:57:15
问题 I am working on a portal to make it accessible. For that it is required to make dynamic content focusable. In the login page, the Authentication error is dynamic content which is not getting focus when needed. Coding is done in razor engine C# @if (TempData["error"] != null) { @Html.Raw(Resources.Strings.ResourceManager.GetString(TempData["error"].ToString())) } Where p="Authentication failed. Renter your Credentials." In other attempt I had put it in alert box like this- @if (TempData["error

Getting checkbox to display if certain item is selected

倖福魔咒の 提交于 2019-12-25 06:37:29
问题 On my Create.cshtml page I have a dropdownlist: <div class="form-group"> @Html.LabelFor(model => model.activityID, "Assignment", htmlAttributes: new { @class = "control-label col-md-2 required" }) <div class="col-md-10"> @Html.DropDownList("activityID", null, "-- Select Activity --", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.activityID, null, new { @class = "text-danger" }) </div> </div> And based on the selection of the user, I need a checkbox

ASP.NET MVC3 | CheckBoxFor(m => m.Go) is unchecked, even though my Model.Go is true

倖福魔咒の 提交于 2019-12-25 05:31:52
问题 I am extremely confused with what is going on. So Go is a boolean variable and in my Model Go is currently resulting to true. How come these two result in a different value? @Html.TextBoxFor(m => m.Go); @Model.Go; @Html.CheckBoxFor(m => m.Go); @Html.TextBoxFor(m => m.Go) Results to FALSE @Html.CheckBoxFor(m => m.Go) Results to an UNCHECKED box (when i'm expected a checked box) @Model.Go Results to TRUE (What I expect to happen) How come @Html.TextBoxFor(m => m.Go) is resulting to false? and

Razor view engine location order not honored?

为君一笑 提交于 2019-12-25 05:31:15
问题 I created a RazorViewEngine subclass to redefine where it looks for views. I set PartialViewLocationFormats string array to contain values "~/Views/{1}/{0}.cshtml", "~/Views/{1}/Partial/{0}.cshtml", "~/Views/Shared/{0}.cshtml", The first and last are there by default. The 2nd one is the one I added, so that I could have a "Partial" subfolder in each "Views/ControllerName" folder for partial views used only by views within that controller, rather than adding them to the "Views/Shared" folder.

Can we have mutiple Submits Button in a View for different operations?

梦想的初衷 提交于 2019-12-25 05:23:32
问题 I have a 4 submit buttons to do different action operation's. For One Submit I have written like this @using (Html.BeginForm("Edit", "Seller", FormMethod.Post)){ } How can we do for multiple Submit buttons ? Do we need to write the same for every Submit button? 回答1: Here is how you do it for two submit buttons, similary you can do this for 'n' submit buttons. Below is a form with two submit buttons. Note that both these submit buttons have the same name i.e “submitButton” @Html.BeginForm(

Why do I get a variable scope error (CS0136) in a Html.HiddenFor?

别来无恙 提交于 2019-12-25 05:22:24
问题 Here is a stripped-down code snippet from a MVC3/Razor view file: @foreach (var item in Model.Stuff.Items){ <tr> <td>@item.Title</td> </tr> <tr> <td> @using (Html.BeginForm()) { @item.Title @Html.HiddenFor(item => item.Title) } </td> </tr> } @* End of Items foreach loop *@ The title shows on the first row. It also shows inside the form. But trying to use it in the HiddenFor I get error CS0136: A local variable named 'item' cannot be declared in this scope because it would give a different

How to fetch selected value from a dropdownlist in MVC3

若如初见. 提交于 2019-12-25 05:14:56
问题 This may sound simple but i am stuck up at a very strange problem. I have created dropdown's in my application and i am not able to fetch the selected value On Edit. Here is my View: <div class="editor-field"> @Html.DropDownListFor(model => model.Hobbyhome.HobbyHomeAddressList.First().ProvincialState.ProvincialStateID, new SelectList(ViewBag.State, "ProvincialStateID", "ProvincialStateName"), "-----Select State-----", new { @id = "State" })<font color="red">*</font> </div> i have written a