asp.net-mvc-views

MVC 5 ViewBag security

六月ゝ 毕业季﹏ 提交于 2021-01-27 14:29:05
问题 I am coding an MVC internet application, and I have a question in regards to using the ViewBag. In many of my controllers, I have SelectList objects, where the user can select an object. The object that is selected is a foreign key value for my model. My question is this: Should I use ViewBag for this? How secure is the ViewBag? Should I use values in my ViewModel instead of the ViewBag? Thanks in advance. 回答1: Use your view model. When the ViewBag was implemented (MVC 3) dynamic typing was

MVC 4 - how do I pass model data to a partial view?

回眸只為那壹抹淺笑 提交于 2019-12-28 05:57:47
问题 I'm building a profile page that will have a number of sections that relate to a particular model (Tenant) - AboutMe, MyPreferences - those kind of things. Each one of those sections is going to be a partial view, to allow for partial page updates using AJAX. When I click on an ActionResult in the TenantController I'm able to create a strongly typed view and the model data is passed to the view fine. I can't achieve this with partial views. I've created a partial view _TenantDetailsPartial :

MVC 4 - how do I pass model data to a partial view?

送分小仙女□ 提交于 2019-12-28 05:57:07
问题 I'm building a profile page that will have a number of sections that relate to a particular model (Tenant) - AboutMe, MyPreferences - those kind of things. Each one of those sections is going to be a partial view, to allow for partial page updates using AJAX. When I click on an ActionResult in the TenantController I'm able to create a strongly typed view and the model data is passed to the view fine. I can't achieve this with partial views. I've created a partial view _TenantDetailsPartial :

MVC5 view drop down list

空扰寡人 提交于 2019-12-21 03:18:09
问题 In a C# MVC5 Internet application view, how can I display a dropdown list for a user to select a list item that is populated from a View Model list? Here is the ViewModel code: public class MapLocationItemViewModel { [Editable(false)] public int mapLocationForeignKeyId { get; set; } public List<string> mapLocationItemTypes { get; set; } public MapLocationItem mapLocationItem { get; set; } } Here is the code that I currently have in the View : <div class="form-group"> @Html.LabelFor(model =>

How to render a Section in a Partial View in MVC3?

两盒软妹~` 提交于 2019-12-17 03:34:05
问题 In a MVC3 project, I have a "_Layout.vbhtml" file with this code <!DOCTYPE html> <html> <head> </head> <body> ... <script src="@Url.Content("~/Scripts/jquery-1.8.2.min.js")"></script> @RenderSection("Scripts", false) </body> </html> Then, I have a Partial View "ValidationScripts.vbhtml" in the Shared folder with @Section Scripts <script src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script> <script

Insert view with collection property

筅森魡賤 提交于 2019-12-13 19:17:58
问题 I have a Person class and a Contact class. A person can have many contacts. public class Person { [Required] public string FirstName { get; set; } public string LastName { get; set; } public string Notes { get; set; } [Required] public List<Contact> Contacts { get; set; } public Person() { Contacts = new List<Contact>(); } } public class Contact { [Required] public string Title { get; set; } [Required] public string Value { get; set; } public Contact() { Title = ""; Value = ""; } public

How can I loop through my table to display contents side by side in MVC Razor View?

为君一笑 提交于 2019-12-13 05:07:27
问题 Hi i want help in putting contents side by side. Right now i can display content separately in left side and right side. But i need to display records from database. For this i am using foreach loop. So how i need to display is 1st records on left side and 2nd record on right side and 3rd on left and so on. How can i loop through like this. I am stucked here.I need help.. I am using this code but all the contents are displaying as i told earlier. <body> @foreach (var item in Model) { <!--

MVC4 View Multiple Submit Buttons - Update label text

廉价感情. 提交于 2019-12-11 12:47:14
问题 At the moment I am working on a MVC4 view with multiple submit buttons. To handle the submit of the different buttons, I use this class: http://blog.maartenballiauw.be/post/2009/11/26/Supporting-multiple-submit-buttons-on-an-ASPNET-MVC-view.aspx I have three buttons and one label: Start Standby Resume How can I display a certain text in that label based on which button is pressed? I wan to use Ajax.BeginForm to update the label text (so I do not have to reload the webpage). Thank you in

how to pass data from View to Controller using ajax get or post in mvc with parameters

二次信任 提交于 2019-12-10 15:48:00
问题 I am trying to pass data from View to Controller Action Method using ajax as follows:- I have Membership instance of user which I passed in from another controller to this view below using viewbag somewhat like this ViewBag.MyUser = MyUser; Now I want to pass 'MyUser' to another Controller form this view using ajax as below. $('#Link').click(function () { $.ajax({ url: http://localhost/Account/Process, type: 'POST', data: '@ViewBag.MyUser', success: function () { }, error: function () { } });

Having to repopulate viewmodel when modelstate is invalid due to not sending all data in such as drop down box list

自古美人都是妖i 提交于 2019-12-07 08:25:15
问题 In my project I create a survey, I link this survey to a company and select users to participate. I select survey template, add extra questions and sets information about the survey such as start and end date. All in all the result is a complex view with data from many parts of the domain. I created a ViewModel for this view that would include things such as a list for all companies (because i need to select company in a drop down list). Now the annoyance is that when i submit to save, if i