razor

MVC5 Lost value in Textbox after Submit

与世无争的帅哥 提交于 2020-02-24 11:08:28
问题 I would like to clarify one thing about MVC5 Razor Views. I was told that I don't have to use HTML Helpers (@Html.EditorFor, @Html.TextBoxFor) in my razor views and it will still work. Controller Code [HttpPost] public ActionResult Create(Models.TestObj obj) { ViewBag.TestStr = string.Format("You typed: {0} {1}", obj.FirstName, obj.LastName); return View(obj); } Razor View @using (Html.BeginForm()) { <div> @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form

kendo grid column with conditionally chosen action

不羁岁月 提交于 2020-02-24 05:51:04
问题 Here is what I got: columns.Bound(t => t.Id) .Title("") .Template(@<text></text>) .ClientTemplate("<a class=\"k-button\" href='" + Url.Action("Edit", "Controller") + "/#=Id#'>Edit</a>") .Width(110); What I need is to pick a specific controller action depending on type of object bound. (different form for e.g. CarEdit when lets say Type==1 and PlaneEdit when Type==2 ) I've done similar thing using JS recently (to produce ClientTemplate content) but would greatly appreciate solution without

MVC Select List with Model at postback, how?

家住魔仙堡 提交于 2020-02-20 05:35:32
问题 I'm trying to create a view that will need 2 dropdown lists with MVC 3. In my only other MVC app we used the Telerik controls that used the Ajax method to populate data. Now on this project we don't use third party controls so I will be using the MVC SelectList for dropdowns. I've been reading a lot of articles on how to populate a SelectList but none of them say the same thing twice, always a different way to create the model, some use ViewData or ViewBag to hold the collections and pass to

Comparions of Razor vs ASPX syntax [closed]

我的未来我决定 提交于 2020-02-19 08:37:30
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . Recently I've been getting into MVC3 and Razor, and reading several articles about these topics to better understand the concept. I've been reading Scott Guthrie's Blog Post, in which he provides the following 2 examples. The first being ASPX syntax, the second being Razor

Provide static file download at server in web application

无人久伴 提交于 2020-02-16 08:04:33
问题 I am working on an MVC 4 web application. On one page I am providing an anchor link which refers to a file on application's directory. The code of the same is - @Html.Action("Download_Static_File", "Charge_Entry", new { File_Path = "../../Content/Templates/Pt_Data/Pt_Data.xls", File_Name = "Pt_Data_Template", value = "Download template" }); My motive is that the file should be downloaded on click. However when I click the link, I get an error like Could not find a part of the path 'C:\Program

Provide static file download at server in web application

坚强是说给别人听的谎言 提交于 2020-02-16 08:03:07
问题 I am working on an MVC 4 web application. On one page I am providing an anchor link which refers to a file on application's directory. The code of the same is - @Html.Action("Download_Static_File", "Charge_Entry", new { File_Path = "../../Content/Templates/Pt_Data/Pt_Data.xls", File_Name = "Pt_Data_Template", value = "Download template" }); My motive is that the file should be downloaded on click. However when I click the link, I get an error like Could not find a part of the path 'C:\Program

Disable Validation on a single (disabled) @Html.EditorFor

白昼怎懂夜的黑 提交于 2020-02-16 06:55:19
问题 I've read around that the given way of doing this seems to be having different view models (which is a bit overkill imo) for different actions/controllers. I thought @Html.EditorFor(model => model.Ingredient.Name, new { htmlAttributes = new { @class = "form-control", disabled = "disabled", data_val = "false"} }) might work but unfortunately not. Does anyone have any ideas? 回答1: MVC can be funny when it comes to declaring elements as disabled. I used readonly instead to get around this issue.

Show multiple models in a single view using ViewModel in Razor MVC3 (with only Details in view)

久未见 提交于 2020-02-15 08:10:03
问题 My task is to show multiple models into a single view.I've created a ViewModel for my requirement but I'm not meeting my requirement. please have a look into the below code and rectify me where m i going wrong ??? public partial class StudentsDetail { public int StudentID { get; set; } public int ParentID { get; set; } public string StudentName { get; set; } public string Gender { get; set; } public string FatherName { get; set; } public string MotherName { get; set; } public Nullable<System

How to render JavaScript into MasterLayout section from partial view?

可紊 提交于 2020-02-09 06:52:39
问题 Given MVC3 and Razor engine, I got _MasterLayout.cshtml @RenderSection("JavaScript", required: false) .. .. @RenderBody() .. View.cshtml with _MasterLayout.cshtml defined in _ViewStart.cshtml .. @Html.RenderAction("PartialView", "PartialController") .. PartialView.cshtml .. @section JavaScript { ........ } .. How can I make sure that JavaScript from Partial View ends up in the Master Layout section? Edit The above scenario doesn't work because the partial view doesn't have a master layout

How to render JavaScript into MasterLayout section from partial view?

和自甴很熟 提交于 2020-02-09 06:52:22
问题 Given MVC3 and Razor engine, I got _MasterLayout.cshtml @RenderSection("JavaScript", required: false) .. .. @RenderBody() .. View.cshtml with _MasterLayout.cshtml defined in _ViewStart.cshtml .. @Html.RenderAction("PartialView", "PartialController") .. PartialView.cshtml .. @section JavaScript { ........ } .. How can I make sure that JavaScript from Partial View ends up in the Master Layout section? Edit The above scenario doesn't work because the partial view doesn't have a master layout