razor

What is the difference between “@Scripts.Render” and “<script>”? [duplicate]

廉价感情. 提交于 2019-12-19 06:33:56
问题 This question already has answers here : Why use @Scripts.Render(“~/bundles/jquery”) (2 answers) Closed 6 years ago . I want to know about the difference between @Scripts.Render("~/something.js") and <script type="text/javascript" src="/something.js"></script> . Yes, I've already searched about this subject, but with no success. I think if @Scripts.Render exists isn't by chance. More details What I'm meaning is: when I should use one or other and why. 回答1: Scripts.Render is used for bundling,

What is the difference between “@Scripts.Render” and “<script>”? [duplicate]

一个人想着一个人 提交于 2019-12-19 06:33:27
问题 This question already has answers here : Why use @Scripts.Render(“~/bundles/jquery”) (2 answers) Closed 6 years ago . I want to know about the difference between @Scripts.Render("~/something.js") and <script type="text/javascript" src="/something.js"></script> . Yes, I've already searched about this subject, but with no success. I think if @Scripts.Render exists isn't by chance. More details What I'm meaning is: when I should use one or other and why. 回答1: Scripts.Render is used for bundling,

Use DELETE form method in Html.BeginForm()?

别来无恙 提交于 2019-12-19 06:26:19
问题 I'd like to use the appropriate HTTP method when possible. In this case, when a button is clicked to delete something, I want to fire the controller action with the attribute [HttpDelete] . However, I can't seem to create a form with this method - using Razor syntax. The FormMethod enum does not have an option for Delete and doing the following doesn't override it: @using (Html.BeginForm("Order", "Users", FormMethod.Post, new { method = "DELETE" })) Searching for solutions yields none, is

Using in Razor VB.net MVC not work as expected

佐手、 提交于 2019-12-19 06:08:27
问题 I'm not sure why this syntax complain error "Enter is not declared. May be inaccessible due to protection level" and must put "@html(" to get rid the error. This block complain error @Using (Html.BeginForm("GetUser", "UserProfile", FormMethod.Post)) Enter User id :- @Html.TextBox("UserId",Model) -- This line must write in this way @Html("Enter User id :-") <input type="submit" value="Submit data" /> --This line complain ">" expected" End Using If rewrite the code in this way, the complain

Tilde Slash Paths Not Working in MVC 4

試著忘記壹切 提交于 2019-12-19 05:46:49
问题 As I understand it, a plain ol' "~/foo" path is supposed to work like @Url.Content("~/") in MVC 4. However, I'm trying to do this and getting many broken paths -- the tilde is still there when the HTML is output. So, for example, I have this path in /Views/Shared/_Layout.cshtml: <link href="~/Content/Site.css" rel="stylesheet" type="text/css" /> And the HTML delivered looks like this: <link href="~/Content/Site.css" rel="stylesheet" type="text/css" /> I'm pretty sure I have this running as an

Select a default value in dropdownlistfor MVC 4

a 夏天 提交于 2019-12-19 05:32:24
问题 I'm trying to make a dropdownlistfor with a selected value but it doesn't work :/ And I search on the web but I don't find the solution :/ For the moment, I'm doing this : In C# : ViewBag.ID_VEH = new SelectList(db.VEHI, "ID_VEH", "COD_VEH", 4); // 4 is an example In my cshtml : @Html.DropDownListFor(model => model.ID_VEH, ViewBag.ID_VEH as SelectList) The dropdownlist is well complete but the default value is not selected :/ do you have an idea please ? 回答1: What I like to do is add a list

DropDownListFor enums in EF5

做~自己de王妃 提交于 2019-12-19 05:16:24
问题 using MVC4 Razor and Entityframework 5. I have a table called organisation with a integer TypeID field which i have created an enum type. In the code i can set and compare the typeid using the enum. public enum OrganisationType : int { Company = 1, Department = 2, Location = 4 } However when i generate the create.cshtml either using the default vs2012 mvc 4 razor templates, or the via the mvcscaffolding nuget package both ignore the TypeID field. I was thinking of amending the tt templates so

using string.Format in MVC Razor view page

一个人想着一个人 提交于 2019-12-19 05:06:44
问题 I want to render images in a Razor view using string.Format like this ... foreach (var p in @Model.Photos) { string.Format("<img src='{0}' width='100' alt='{1}' />", p.Path, p.AlternateText); } Something is clearly wrong here, because on rendering this page, I've got nothing inside this section. 回答1: string.Format() returns a string, which you're discarding. You need to print that string to the page: @string.Format(...) Note that since this isn't a statement, there shouldn't be a ; . Also

Ajax post in MVC 3 with multiple-form View

只愿长相守 提交于 2019-12-19 04:42:51
问题 I deleted my prior question dealing with the subject as the context has changed a bit and the problem is new. I have a single view now, with a single model. The view has 2 forms. Each form submits to its own action, each action uses a subset of the model data, uses the data to perform a search. The search results then are added to a property of the model and need to be rendered back to the view. I'm able to accomplish this all via a standard html post but this now needs to be an ajax post.

MVC model not binding to dictionary

家住魔仙堡 提交于 2019-12-19 04:25:48
问题 I am using ASP.Net MVC4 (Razor). I have the following code: Dictionary<string, OccasionObject> occasionList = new Dictionary<string, OccasionObject>() The key is a string of the category of the occasion. The occassion object has 3 properties: isAttending(bool) , ID(int) , and Name(string) In my cshtml file, I do the following: @foreach(string s in model.occasionList .Keys) { foreach(var o in model.occasionList .Keys[s]) { @Html.CheckBoxFor(m=>m.occasionList[s].FirstOrDefault(ev=>ev.ID == o.ID