razor

MVC-binder fails to bind complex-viewmodel-property in form submit

本秂侑毒 提交于 2019-12-25 08:47:52
问题 I'm using Umbraco MVC to build a form four our webpage. I have a ViewModel which is actually a property to another ViewModel, and is populated using a partial-view in the razor-form below. For whatever reason, the sub-viewmodel (RequiredHealthInputData, se below) is always null after binding! The binder will successfully bind all the form values to my main viewmodel but my sub-viewmodel will remain null! (I have research many similar questions regarding binding of complex types but I believe

How to invoke javascript method based on a Value of ViewBag

扶醉桌前 提交于 2019-12-25 08:36:22
问题 I'm working on small mvc application, and on my view there is tab control which has 3 tabs, and depending on ViewBag value I need to open my third tab, here is image of a how my view looks: So when View is loaded, I need to check for a value of my ViewBag and depending on that I need to open my TAB 3, so here is what I've tried: <div class="" role="tabpanel" data-example-id="togglable-tabs"> <ul id="myTab" class="nav nav-tabs bar_tabs" role="tablist"> @if (ViewBag.SuccessBody == null) { <li

Best method for determining if a row exists

一个人想着一个人 提交于 2019-12-25 08:28:38
问题 I am using SQL Server and WebMatrix Razor syntax to try and determine is a username is contained within a table called Users. The logic I wish to have is : bool usernameExists = db.QueryValue("SELECT Username from Users where Username = ?", username); if(usernameExists.IsEmpty()){ //username is not in table Response.Redirect("Register.cshtml"); } What is the best practice for going about this? 回答1: Simplest is probably: bool usernameExists = db.QueryValue("SELECT usernameExists = CASE WHEN

How can edit the value of Html.TextBoxFor in controller before use it?

断了今生、忘了曾经 提交于 2019-12-25 08:27:49
问题 I'm working on my project in MVC 3 and searching for a way, which can add this functionality to all my Html.TextboxFor: When user type "foo" and submit form, in controller level I get it by model as "fuu" for example. I need this feature to replace some Unicode characters by some others. Let I show my code in View and Controller: View: @Html.TextBoxFor(model => model.Title) // user will type "foo", in TitleTexbox! Controller: [HttpPost] public virtual ActionResult Create(MyModel model) { var

change cell styling in KendoGrid

丶灬走出姿态 提交于 2019-12-25 08:27:40
问题 Just discovered the KendoGrid and was trying to change the style of an individual column(cell) after changing another cellvalue. For example I have a grid with a shipname and shipcity column. Suppose I have a business rule that says : 'Make shipcity cell value disabled when the shipname on the same row has the same value' I found this sample which uses the blur event which I probably use, what would be a good way of implementing this rule? Also nice to know your opinion in relation to asp.net

Radio buttons and checkboxes grouped together MVC

情到浓时终转凉″ 提交于 2019-12-25 08:26:43
问题 I'm trying to find an MVC (razor) solution where I can use radio buttons and checkboxes together. Say there are 2 radiobuttons labelled: All people and Family Members . If you select the "Family Members" radio button , 3 checkboxes should be enabled: "Employee", "Spouse", "Dependant(s)" The questions are: How to group a radio button to 3 checkboxes? How to enable the checkboxes when the related radio button is selected? 回答1: Well you could do the following: <ul> <li><input type="radio">All

How does Html.EditorFor process changes to the model

空扰寡人 提交于 2019-12-25 08:16:46
问题 I'm trying to figure out why why and how EditorFor caches information. This is a simple program that has one two textareas. One for input and one for output. The reason for a text area for output is that it makes a select all copy easier. My code is pretty simple. First my controller puts some default value public ActionResult MoveCss() { MoveCssIO model = new MoveCssIO(); ; model.InputCss = "Fish"; return View(model); } Then my model kicks in and makes output the uppercase of input [Required

View or Hide a dropdownlist in my razor view using helper method

陌路散爱 提交于 2019-12-25 08:15:52
问题 I have an object named Visit and i defined the following helper method (“CanBeEdited”) to specify if users can edit the object Status property or not:- public partial class Visit { public bool CanBeEdited(string username) {return (((DoctorID != null) && (DoctorID.ToUpper().Equals(username.ToUpper()))) && (StatusID == 5)); } }} Then i have specified to show or hide certain dropdownlist on my Edit view depending on weather the CanBeEdited helper method returns true or false (if it returns true

MVC3 & EF. Interface for TDD

房东的猫 提交于 2019-12-25 07:58:23
问题 Can somebody please explain: I am using MVC3/C#/Razor to build a project to get used to using MVC. I am using the inbuilt account controller. I am storing the account data in my local SQL database using Entity Framework to connect. How can I easily generate interfaces for EF? SO FAR I am using the plugin from: http://blog.johanneshoppe.de/2010/10/walkthrough-ado-net-unit-testable-repository-generator/#step1 This allows me to have an interface for my entities already created. However, I know

Model properties null on Ajax post from list box change event

99封情书 提交于 2019-12-25 07:41:54
问题 I have a view which contains a list box. when users click on an item in the list box I have to post to a controller action method to see the value of the items selected/de-selected in the list box. So it is posting to the controller action but the model is posted as null. When I post to the controller, I do serialize the form. In other pages of my application when I serialize the form and post to the controller, the model is never null. I am not sure whats going on in this page but here is