Search Results

Search found 29 results on 2 pages for 'checkboxfor'.

Page 1/2 | 1 2  | Next Page >

  • Setting html attribute that is reserved keyword in Html.CheckBoxFor in ASP.NET MVC

    - by dormisher
    Hi, I am using the HtmlHelper to create a checkbox in my view like so: <%= Html.CheckBoxFor(model = model.SeatOnly, new { checked = "checked" })% However, an error is being thrown as checked is a reserved keyword. I have found a couple of people saying that you must use the 'reserved word prefix' and simply put an uderscore in front of the attribute like so: <%= Html.CheckBoxFor(model = model.SeatOnly, new { _checked = "checked" })% This does not generate an error but in the generated html the attribute is actually '_checked' which means it doesn't work (if I use firebug and remove the underscore the attribute then takes effect). Does anyone know a way around this while still using CheckBoxFor? Thanks

    Read the article

  • Html.CheckBoxFor() checked problem in ASP.Net MVC 2

    - by inolen
    It doesn't seem that the Html.CheckBoxFor helper adds the correct "checked" attribute when rendering the HTML. I have a bool property rendered like so: <%= Html.CheckBoxFor(m => m.Visible) %> And the outputted HTML is this: <input type="checkbox" value="true" name="Visible" id="Visible"> Is there some particular reason it does not add the "checked" attribute when the value is true?

    Read the article

  • Html.CheckBoxFor() checked problem in ASP.Net MVC 2

    - by inolen
    It doesn't seem that the Html.CheckBoxFor helper adds the correct "checked" attribute when rendering the HTML. I have a bool property rendered like so: <%= Html.CheckBoxFor(m => m.Visible) %> And the outputted HTML is this: <input type="checkbox" value="true" name="Visible" id="Visible"> Is there some particular reason it does not add the "checked" attribute when the value is true?

    Read the article

  • ASP.NET MVC:Why does the CheckBoxFor render an additional input tag and how can I get the value usin

    - by Nikron
    Hi, In my ASP.NET MVC app I am rendering out a checkbox using the following code: <%= Html.CheckBoxFor(i=>i.ReceiveRSVPNotifications) %> Now I see that this renders both the checkbox input tag and a hidden input tag. The problem that I am having is when I try retrieve the value from the checkbox using the FormCollection: FormValues["ReceiveRSVPNotifications"] I get the value "true,false". When looking at the rendered out HTML I can see the following: <input id="ReceiveRSVPNotifications" name="ReceiveRSVPNotifications" value="true" type="checkbox"> <input name="ReceiveRSVPNotifications" value="false" type="hidden"> So the FormValues collection seems to join these two values since they have the same name. Any Ideas?

    Read the article

  • ASP.NET MVC 2 InputExtensions different on server than local machine

    - by Mike
    Hi everyone, So this is kind of a crazy problem to me, but I've had no luck Googling it. I have an ASP.NET MVC 2 application (under .NET 4.0) running locally just fine. When I upload it to my production server (under shared hosting) I get Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'TextBoxFor' and no extension method 'TextBoxFor' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?) for this code: <%= this.Html.TextBoxFor(person => person.LastName) %> This is one of the new standard extension methods in MVC 2. So I wrote some diagnostic code: System.Reflection.Assembly ass = System.Reflection.Assembly.GetAssembly(typeof(InputExtensions)); Response.Write("From GAC: " + ass.GlobalAssemblyCache.ToString() + "<br/>"); Response.Write("ImageRuntimeVersion: " + ass.ImageRuntimeVersion.ToString() + "<br/>"); Response.Write("Version: " + System.Diagnostics.FileVersionInfo.GetVersionInfo(ass.Location).ToString() + "<br/>"); foreach (var method in typeof(InputExtensions).GetMethods()) { Response.Write(method.Name + "<br/>"); } running locally (where it works fine), I get this as output: From GAC: True ImageRuntimeVersion: v2.0.50727 Version: File: C:\Windows\assembly\GAC_MSIL\System.Web.Mvc\2.0.0.0__31bf3856ad364e35\System.Web.Mvc.dll InternalName: System.Web.Mvc.dll OriginalFilename: System.Web.Mvc.dll FileVersion: 2.0.50217.0 FileDescription: System.Web.Mvc.dll Product: Microsoft® .NET Framework ProductVersion: 2.0.50217.0 Debug: False Patched: False PreRelease: False PrivateBuild: False SpecialBuild: False Language: Language Neutral CheckBox CheckBox CheckBox CheckBox CheckBox CheckBox CheckBoxFor CheckBoxFor CheckBoxFor Hidden Hidden Hidden Hidden HiddenFor HiddenFor HiddenFor Password Password Password Password PasswordFor PasswordFor PasswordFor RadioButton RadioButton RadioButton RadioButton RadioButton RadioButton RadioButtonFor RadioButtonFor RadioButtonFor TextBox TextBox TextBox TextBox TextBoxFor TextBoxFor TextBoxFor ToString Equals GetHashCode GetType and when running on the production server (where it fails), I see: From GAC: True ImageRuntimeVersion: v2.0.50727 Version: File: C:\Windows\assembly\GAC_MSIL\System.Web.Mvc\2.0.0.0__31bf3856ad364e35\System.Web.Mvc.dll InternalName: System.Web.Mvc.dll OriginalFilename: System.Web.Mvc.dll FileVersion: 2.0.41001.0 FileDescription: System.Web.Mvc.dll Product: Microsoft® .NET Framework ProductVersion: 2.0.41001.0 Debug: False Patched: False PreRelease: False PrivateBuild: False SpecialBuild: False Language: Language Neutral CheckBox CheckBox CheckBox CheckBox CheckBox CheckBox Hidden Hidden Hidden Hidden Hidden Hidden Password Password Password Password RadioButton RadioButton RadioButton RadioButton RadioButton RadioButton TextBox TextBox TextBox TextBox ToString Equals GetHashCode GetType note that "TextBoxFor" is not present (hence the error). I have MVC referenced in the csproj: <Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <SpecificVersion>True</SpecificVersion> <HintPath>References\System.Web.Mvc.dll</HintPath> <Private>True</Private> </Reference> I just can't figure it what to do next. Thoughts? Thanks! -Mike

    Read the article

  • ASP.NET MVC Conditional validation

    - by Peter Stegnar
    How to use data annotations to do a conditional validation on model? For example, lets say we have the following model (Person and Senior): public class Person { [Required(ErrorMessage = "*")] public string Name { get; set; } public bool IsSenior { get; set; } public Senior Senior { get; set; } } public class Senior { [Required(ErrorMessage = "*")]//this should be conditional validation, based on the "IsSenior" value public string Description { get; set; } } And the following view: <%= Html.EditorFor(m => m.Name)%> <%= Html.ValidationMessageFor(m => m.Name)%> <%= Html.CheckBoxFor(m => m.IsSenior)%> <%= Html.ValidationMessageFor(m => m.IsSenior)%> <%= Html.CheckBoxFor(m => m.Senior.Description)%> <%= Html.ValidationMessageFor(m => m.Senior.Description)%> I would like to be the "Senior.Description" property conditional required field based on the selection of the "IsSenior" propery (true - required). How to implement conditional validation in ASP.NET MVC 2 with data annotations? UPDATE Found nice solution. Look below.

    Read the article

  • MVC map to nullable bool in model

    - by fearofawhackplanet
    With a view model containing the field: public bool? IsDefault { get; set; } I get an error when trying to map in the view: <%= Html.CheckBoxFor(model => model.IsDefault) %> Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) I've tried casting, and using .Value and neither worked. Note the behaviour I would like is that submitting the form should set IsDefault in the model to true or false. A value of null simply means that the model has not been populated.

    Read the article

  • How to handle Booleans/CheckBoxes in ASP.NET MVC 2 with DataAnnotations?

    - by asp_net
    I've got a view model like this: public class SignUpViewModel { [Required(ErrorMessage = "Bitte lesen und akzeptieren Sie die AGB.")] [DisplayName("Ich habe die AGB gelesen und akzeptiere diese.")] public bool AgreesWithTerms { get; set; } } The view markup code: <%= Html.CheckBoxFor(m => m.AgreesWithTerms) %> <%= Html.LabelFor(m => m.AgreesWithTerms)%> The result: No validation is executed. That's okay so far because bool is a value type and never null. But even if I make AgreesWithTerms nullable it won't work because the compiler shouts "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions." So, what's the correct way to handle this?

    Read the article

  • html.checkbox - explicit value to hidden field value

    - by Tassadaque
    Hi I am creating list of checkboxes in partial view by follwoing http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/ code and Rendered HTML for checkboxes is as follows <%=Html.CheckBox("EmployeeID", new { value = user.EmployeeID, @class = "ccboxes", title = user.Designation + "(" + user.EmployeeName + ")" })%> <INPUT id=MemoUsers_a29f82e4-ebbc-47b0-8cdd-7d54f94143be__EmployeeID class=boxes title=Programmer(Zia) value=6 type=checkbox name=MemoUsers[a29f82e4-ebbc-47b0-8cdd-7d54f94143be].EmployeeID jQuery1276681299292="27"> <INPUT value=false type=hidden name=MemoUsers[a29f82e4-ebbc-47b0-8cdd-7d54f94143be].EmployeeID> In rendered html it can be seen that value attribute of hidden field is false. i want to assign explicit value(same as checkbox value) to this value. Is this possible using html.checkbox or html.checkboxfor. one way is recommended in http://stackoverflow.com/questions/626901/asp-net-mvc-rc2-checkboxes-with-explicit-values. Is there any other better way i want to do this as ModelState.IsValid is returning false because of hidden field value attribute Regards

    Read the article

  • How to binding to bit datatype in SQL to Booleans/CheckBoxes in ASP.NET MVC 2 with DataAnnotations

    - by nvtthang
    I've got problem with binding data type boolean to checkbox in MVC 2 data annotations Here's my code sample: label> Is Hot </label> <%=Html.CheckBoxFor(model => model.isHot, new {@class="input" })%> It always raise this error message below at (model=model.isHot). Cannot convert lambda expression to delegate type 'System.Func<Framework.Models.customer,bool>' because some of the return types in the block are not implicitly convertible to the delegate return type Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) Please suggest me how can I solve this problem? Thanks in advance.

    Read the article

  • How to require a checkbox to be checked at client side before form gets submitted to server in MVC 3?

    - by Projapati
    I have a Terms and Condition checkbox on my signup page. I want to make it required like my few other fields on the form before posting to server. This validation must be done at client side. Anyone knows how to do it properly? I am using MVC 3, jquery.validate.min.js and jquery.validate.unobtrusive.min.js Model: [Required(ErrorMessage = "terms and condition")] [Display(Name = "terms")] public bool Terms { get; set; } View: @Html.CheckBoxFor(m => m.Terms, new { @class = "cb" }) Terms & Condition <button type="submit" id="btnSubmit" class="btn">Signup</button> Also, Is it possible to call/trap some JS function when the submit button is clicked? That way I can easily use jquery to do validation and then submit? Thanks for reading

    Read the article

  • Passing viewmodel to actionresult creates new viewmodel

    - by Jonas Bohez
    I am using a viewmodel, which i then when to send to an actionresult to use (the modified viewmodel) But in the controller, i lose the list and objects in my viewmodel. This is my view: @using PigeonFancier.Models @model PigeonFancier.Models.InschrijvingModel @using (Html.BeginForm("UpdateInschrijvingen","Melker",Model)) { <div> <fieldset> <table> @foreach (var item in Model.inschrijvingLijst) { <tr> <td>@Html.DisplayFor(model => item.Duif.Naam)</td> <td> @Html.CheckBoxFor(model => item.isGeselecteerd)</td> </tr> } </table> <input type="submit" value="Wijzigen"/> </fieldset> </div> } This is my controller, which does nothing at the moment until i can get the full viewmodel back from the view. public ActionResult UpdateInschrijvingen(InschrijvingModel inschrijvingsModel) { // inschrijvingsModel is not null, but it creates a new model before it comes here with //Use the model for some updates return RedirectToAction("Inschrijven", new { vluchtId = inschrijvingsModel.vlucht.VluchtId }); } This is the model with the List and some other objects who become null because it creates a new model when it comes back from the view to the actionresult public class InschrijvingModel { public Vlucht vlucht; public Duivenmelker duivenmelker; public List<CheckBoxModel> inschrijvingLijst { get; set; } public InschrijvingModel() { // Without this i get, No parameterless constructor defined exception. // So it uses this when it comes back from the view to make a new model } public InschrijvingModel(Duivenmelker m, Vlucht vl) { inschrijvingLijst = new List<CheckBoxModel>(); vlucht = vl; duivenmelker = m; foreach (var i in m.Duiven) { inschrijvingLijst.Add(new CheckBoxModel(){Duif = i, isGeselecteerd = i.IsIngeschrevenOpVlucht(vl)}); } } What is going wrong and how should i fix this problem please? Thanks

    Read the article

  • Bind postback data from a strong type view of type List<T>

    - by Robert Koritnik
    I have a strong type view of type List<List<MyViewModelClass>> The outer list will always have two lists of List<MyViewModelClass>. For each of the two outer lists I want to display a group of checkboxes. Each set can have an arbitrary number of choices. My view model class looks similar to this: public class MyViewModelClass { public Area Area { get; set; } public bool IsGeneric { get; set; } public string Code { get; set; } public bool IsChecked { get; set; } } So the final view will look something like: Please select those that apply: First set of choices: x Option 1 x Option 2 x Option 3 etc. Second set of choices: x Second Option 1 x Second Option 2 x Second Option 3 x Second Option 4 etc. Checkboxes should display MyViewModelClass.Area.Name, and their value should be related to MyViewModelClass.Area.Id. Checked state is of course related to MyViewModel.IsChecked. Question I wonder how should I use Html.CheckBox() or Html.CheckBoxFor() helper to display my checkboxes? I have to get these values back to the server on a postback of course. I would like to have my controller action like one of these: public ActionResult ConsumeSelections(List<List<MyViewModelClass>> data) { // process data } public ActionResult ConsumeSelections(List<MyViewModelClass> first, List<MyViewModelClass> second) { // process data } If it makes things simpler, I could make a separate view model type like: public class Options { public List First { get; set; } public List Second { get; set; } } As well as changing my first version of controller action to: public ActionResult ConsumeSelections(Options data) { // process data }

    Read the article

  • How to bind data from a view of type List<List<MyViewModelClass>>?

    - by Robert Koritnik
    I have a strong type view of type List<List<MyViewModelClass>> The outer list will always have two lists of List<MyViewModelClass>. For each of the two outer lists I want to display a group of checkboxes. Each set can have an arbitrary number of choices. My view model class looks similar to this: public class MyViewModelClass { public Area Area { get; set; } public bool IsGeneric { get; set; } public string Code { get; set; } public bool IsChecked { get; set; } } So the final view will look something like: Please select those that apply: First set of choices: x Option 1 x Option 2 x Option 3 etc. Second set of choices: x Second Option 1 x Second Option 2 x Second Option 3 x Second Option 4 etc. Checkboxes should display MyViewModelClass.Area.Name, and their value should be related to MyViewModelClass.Area.Id. Checked state is of course related to MyViewModel.IsChecked. Question I wonder how should I use Html.CheckBox() or Html.CheckBoxFor() helper to display my checkboxes? I have to get these values back to the server on a postback of course. If it makes things simpler, I could make a separate view model type like: public class Options { public List<MyViewModelClass> General { get; set; } public List<MyViewModelClass> Others { get; set; } }

    Read the article

  • HOWTO: implement a jQuery version of ASP.Net MVC "Strongly Typed Partial Views"

    - by Sam Carleton
    I am working on a multi-page assessment form where the questions/responses are database driven. Currently I the basic system working with Html.BeginForm via standard ASP.Net MVC. At this point in time, the key to the whole system is the 'Strongly Typed Partial Views'. When the question/response is read from the database, the response type determines which derived model is created and added to the collection. The main view it iterates through the collection and uses the 'Strongly Typed Partial Views' system of ASP.Net MVC to determine which view to render the correct type of response (radio button, drop down, or text box). I would like to change this process from a Html.BeginForm to Ajax.BeginForm. The problem is I don't have a clue as to how to implement the dynamic creation of the question/response in the JavaScript/jQuery world. Any thoughts and/or suggestions? Here is the current code to generate the dynamic form: @using (Html.BeginForm(new { mdsId = @Model.MdsId, sectionId = @Model.SectionId })) { <div class="SectionTitle"> <span>Section @Model.SectionName - @Model.SectionDescription</span> <span style="float: right">@Html.CheckBoxFor(x => x.ShowUnansweredQuestions) Show only unaswered questions</span> </div> @Html.HiddenFor(x => x.PrevSectionId) @Html.HiddenFor(x => x.NextSectionId) for (var i = 0; i < Model.answers.Count(); i++) { @Html.EditorFor(m => m.answers[i]); } }

    Read the article

  • MVC3 View For Loop values initialization

    - by Ryan
    So I have a for loop in my View that is supposed to render out the input boxes. Now inside these input boxes I want to put lables that disappear when you click on them. This is all simple. Now it's probably because my brain was wired for php first, and it has been difficult to get it to think in lambdas and object orientation, but I can't figure out how to do this: @{ for (int i = 0; i < 3; i++) { <div class="editor-label grid_2">User</div> Model.Users[i].UserFirstName = "First Name"; Model.Users[i].UserLastName = "Last Name"; Model.Users[i].UserEmailAddress = "Email Address"; <div class="grid_10"> @Html.TextBoxFor(m => Model.Users[i].UserFirstName, new { @class = "user-input" }) @Html.TextBoxFor(m => Model.Users[i].UserLastName, new { @class = "user-input" }) @Html.TextBoxFor(m => Model.Users[i].UserEmailAddress, new { @class = "user-input-long" }) @Html.CheckBoxFor(m => Model.Users[i].IsUserAdmin) <span>&nbsp;admin?</span> </div> <div class="clear"> </div> } } And initialize the values for the users. And you're probably thinking "Of course that won't work. You're going to get a Null Reference Exception", and you would be correct. I might need to initialize them somewhere else and I don't realize it but I'm just not sure. I've tried the [DefaultValue("First Name")] route and that doesn't work. I'm probably thinking about this wrong, but my brain is already shot from trying to figure out how to wire up these events to the controller, so any help would be appreciated!

    Read the article

  • Model value not being set on return from View to Controller

    - by sagesky36
    I have a boolean model variable who's value is supposed to be set to TRUE in order to perform a process on return back into the Controller. It works absolutely fine on my local machine, but not on the remote web server. Can somebody PLEASE inform me what I am missing? Below is the "proof of the pudding": The boolean value in quesion is "ShouldGeneratePdf"; MODEL: namespace PDFConverterModel.ViewModels { public partial class ViewModelTemplate_Guarantors { public ViewModelTemplate_Guarantors() { Templates = new List<PDFTemplate>(); Guarantors = new List<tGuarantor>(); } public int SelectedTemplateId { get; set; } public List<PDFTemplate> Templates { get; set; } public int SelectedGuarantorId { get; set; } public List<tGuarantor> Guarantors { get; set; } public string LoanId { get; set; } public string DepartmentId { get; set; } public bool isRepeat { get; set; } public string ddlDept { get; set; } public string SelectedDeptText { get; set; } public string LoanTypeId { get; set; } public string LoanType { get; set; } public string Error { get; set; } public string ErrorT { get; set; } public string ErrorG { get; set; } public bool ShowGeneratePDFBtn { get; set; } public bool ShouldGeneratePdf { get; set; } } } MasterPage: <!DOCTYPE html> <html> <head> <title>@ViewBag.Title</title> <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Content/kendo/2012.2.913/kendo.common.min.css")" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Content/kendo/2012.2.913/kendo.dataviz.min.css")" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Content/kendo/2012.2.913/kendo.blueopal.min.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/modernizr-2.5.3.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/kendo/2012.2.913/kendo.all.min.js")"></script> <script src="@Url.Content("~/Scripts/kendo/2012.2.913/kendo.aspnetmvc.min.js")"></script> </head> <body> <div class="page"> <header> <div id="title"> <h1>BHG :: PDF Service Generator</h1> </div> </header> <section id="main"> @RenderBody() </section> <footer> </footer> </div> </body> </html> View: @model PDFConverterModel.ViewModels.ViewModelTemplate_Guarantors @using (Html.BeginForm("ProcessForm", "Home", new AjaxOptions { HttpMethod = "POST" })) { <table style="width: 1000px"> @Html.HiddenFor(x => x.ShouldGeneratePdf) <tr> <td> <img alt="BHG Logo" src="~/Images/logo.gif" /> </td> </tr> <tr> <td> @(Html.Kendo().IntegerTextBox() .Placeholder("Enter Loan Id") .Name("LoanId") .Format("{0:#######}") .Value(Convert.ToInt32(Model.LoanId)) ) </td> </tr> <tr> <td>@Html.Label("Loan Type: ") @Html.DisplayFor(model => Model.LoanType) </td> <td> <label for="ddlDept">Department:</label> @(Html.Kendo().DropDownListFor(model => Model.ddlDept) .Name("ddlDept") .DataTextField("DepartmentName") .DataValueField("DepartmentID") .Events(e => e.Change("Refresh")) .DataSource(source => { source.Read(read => { read.Action("GetDepartments", "Home"); }); }) .Value(Model.ddlDept.ToString()) ) </td> </tr> @if (Model.ShowGeneratePDFBtn == true) { if (Model.ErrorT == string.Empty) { <tr> <td> <u><b>@Html.Label("Templates:")</b></u> </td> </tr> <tr> @for (int i = 0; i < Model.Templates.Count; i++) { <td> @Html.CheckBoxFor(model => Model.Templates[i].IsChecked) @Html.DisplayFor(model => Model.Templates[i].TemplateId) </td> } </tr> } else { <tr> <td> <b>@Html.DisplayFor(model => Model.ErrorT)</b> </td> </tr> } if (Model.ErrorG == string.Empty) { <tr> <td> <u><b>@Html.Label("Guarantors:")</b></u> </td> </tr> <tr> @for (int i = 0; i < Model.Guarantors.Count; i++) { <td> @Html.CheckBoxFor(model => Model.Guarantors[i].isChecked) @Html.DisplayFor(model => Model.Guarantors[i].GuarantorFirstName)&nbsp;@Html.DisplayFor(model => Model.Guarantors[i].GuarantorLastName) </td> } </tr> } else { <tr> <td> <b>@Html.DisplayFor(model => Model.ErrorG)</b> </td> </tr> } } <tr> <td> <input type="submit" name="submitbutton" id="btnRefresh" value='Refresh' /> </td> @if (Model.ShowGeneratePDFBtn == true) { <td> <input type="submit" name="submitbutton" id="btnGeneratePDF" value='Generate PDF' /> </td> } </tr> <tr> <td style="color: red; font: bold"> @Model.Error </td> </tr> </table> } <script type="text/javascript"> $('#btnRefresh').click(function () { Refresh(); }); function Refresh() { var LoanID = $("#LoanID").val(); if (parseInt(LoanID) != 0) { $('#ShouldGeneratePdf').val(false) document.forms[0].submit(); } else { alert("Please enter a LoanId"); } } //$(function () { // //DOM loaded // $('#btnGeneratePDF').click(function () { // DisableGeneratePDF(); // $('#ShouldGeneratePdf').val(true) // }); //}); //function DisableGeneratePDF() { // $('#btnGeneratePDF').attr("disabled", true); // $('#btnRefresh').attr("disabled", true); //} $('#btnGeneratePDF').click(function () { alert("inside click function"); DisableGeneratePDF(); $('#ShouldGeneratePdf').val(true) tof = $('#ShouldGeneratePdf').val(); alert("ShouldGeneratePdf set to " + tof); }); function DisableGeneratePDF() { alert("begin DisableGeneratePDF function"); $('#btnGeneratePDF').attr("disabled", true); $('#btnRefresh').attr("disabled", true); alert("end DisableGeneratePDF function"); } </script> Controller: [HttpPost] public ActionResult ProcessForm(string submitbutton, ViewModelTemplate_Guarantors model, FormCollection collection) if ((submitbutton == "Refresh") || (submitbutton == null) && (model.ShouldGeneratePdf == false)) { } else if ((submitbutton == "Generate PDF") || (model.ShouldGeneratePdf == true)) { } The "Alerts" in the script above come out to exactly what they should be on the remote server. The last alert shows that the value of the bool variable is "true". However, when I do page source views of the hidden variable, below is the result. The values of the hidden variable when the page loads and when the last alert button finishes are as follows: My local machine: The remote machine: As you can see, the value on my machine is set to true when the process executes. However, on the remote machine, it is set to false where it then doesn't excute. Why isn't the value in the model being returned as TRUE on the remote machine?

    Read the article

  • ASP.NET MVC3 checkbox dropdownlist create [migrated]

    - by user95381
    i'm new in asp.net MVC and I/m use view model to poppulate the dropdown list and group of checkboxes. I use SQL Server 2012, where have many to many relationships between Students - Books; Student - Cities. I need collect StudentName, one city and many books for one student. I have next questions: 1. How can I get the values from database to my StudentBookCityViewModel? 2. How can I save the values to my database in [HttpPost] Create method? Here is the code: MODEL public class Student { public int StudentId { get; set; } public string StudentName { get; set; } public ICollection<Book> Books { get; set; } public ICollection<City> Cities { get; set; } } public class Book { public int BookId { get; set; } public string BookName { get; set; } public bool IsSelected { get; set; } public ICollection<Student> Students { get; set; } } public class City { public int CityId { get; set; } public string CityName { get; set; } public bool IsSelected { get; set; } public ICollection<Student> Students { get; set; } } VIEW MODEL public class StudentBookCityViewModel { public string StudentName { get; set; } public IList<Book> Books { get; set; } public StudentBookCityViewModel() { Books = new[] { new Book {BookName = "Title1", IsSelected = false}, new Book {BookName = "Title2", IsSelected = false}, new Book {BookName = "Title3", IsSelected = false} }.ToList(); } public string City { get; set; } public IEnumerable<SelectListItem> CityValues { get { return new[] { new SelectListItem {Value = "Value1", Text = "Text1"}, new SelectListItem {Value = "Value2", Text = "Text2"}, new SelectListItem {Value = "Value3", Text = "Text3"} }; } } } Context public class EFDbContext : DbContext{ public EFDbContext(string connectionString) { Database.Connection.ConnectionString = connectionString; } public DbSet<Book> Books { get; set; } public DbSet<Student> Students { get; set; } public DbSet<City> Cities { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Book>() .HasMany(x => x.Students).WithMany(x => x.Books) .Map(x => x.MapLeftKey("BookId").MapRightKey("StudentId").ToTable("StudentBooks")); modelBuilder.Entity<City>() .HasMany(x => x.Students).WithMany(x => x.Cities) .Map(x => x.MapLeftKey("CityId").MapRightKey("StudentId").ToTable("StudentCities")); } } Controller public ActionResult Create() { return View(); } [HttpPost] public ActionResult Create() { //I don't understand how I can save values to db context.SaveChanges(); return RedirectToAction("Index"); } View @model UsingEFNew.ViewModels.StudentBookCityViewModel @using (Html.BeginForm()) { Your Name: @Html.TextBoxFor(model = model.StudentName) <div>Genre:</div> <div> @Html.DropDownListFor(model => model.City, Model.CityValues) </div> <div>Books:</div> <div> @for (int i = 0; i < Model.Books.Count; i++) { <div> @Html.HiddenFor(x => x.Books[i].BookId) @Html.CheckBoxFor(x => x.Books[i].IsSelected) @Html.LabelFor(x => x.Books[i].IsSelected, Model.Books[i].BookName) </div> } </div> <div> <input id="btnSubmit" type="submit" value="Submit" /> </div> </div> }

    Read the article

  • jPlayer widget created with static error as result

    - by goldengel
    I've created a widged with Orchard. Unfortunately I've used the same "Title" for a jPlayer widget twice. Now I receive an error: Server Error in '/wgk' Application. Sequence contains more than one element Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: Sequence contains more than one element Source Error: Line 2: <fieldset> Line 3: <div>@Html.LabelFor(o => o.MediaGalleryName, @T("Media gallery"))</div> Line 4: @if(!Model.HasAvailableGalleries) { Line 5: <div>@T("You need first to create an media gallery on Media Gallery menu")</div> Line 6: } Source File: x:\Intepub\wgk\Modules\Orchard.jPlayer\Views\EditorTemplates\Parts\MediaGallery.cshtml Line: 4 Stack Trace: [InvalidOperationException: Sequence contains more than one element] System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +4206966 NHibernate.Linq.Visitors.ImmediateResultsVisitor`1.HandleSingleOrDefaultCall(MethodCallExpression call) +51 NHibernate.Linq.Visitors.ImmediateResultsVisitor`1.VisitMethodCall(MethodCallExpression call) +411 NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp) +371 In MediaGallery.cshtml (found in error description above) is written: @model Orchard.jPlayer.Models.MediaGalleryPart <fieldset> <div>@Html.LabelFor(o => o.MediaGalleryName, @T("Media gallery"))</div> @if(!Model.HasAvailableGalleries) { <div>@T("You need first to create an media gallery on Media Gallery menu")</div> } else { <div>@Html.DropDownListFor(o => o.SelectedGallery, Model.AvailableGalleries)</div> <div>@Html.LabelFor(o => o.SelectedType, @T("Media gallery type"))</div> <div>@Html.DropDownListFor(o => o.SelectedType, Model.AvailableTypes)</div> <div>@Html.LabelFor(o => o.AutoPlay, @T("Auto play"))</div> <div>@Html.CheckBoxFor(o => o.AutoPlay)</div> } </fieldset> My problem is now, I cannot find or edit the widget with double used name. I would love to replace it to another name. But I do not know where to do this. Please advice.

    Read the article

  • client side validation in ascx files (user controls) for asp.net mvc

    - by Sefer KILIÇ
    hi, I have a logOn forn in ascx files and I render it as partial. How I can add a clinet side validation to this form, have any idea ? My below code does not work <%= Html.ValidationSummary(true, "Giris basarisiz oldu. Lütfen hatalari düzeltip tekrar deneyin.") %> <% Html.EnableClientValidation(); %> <% using (Html.BeginForm("LogOnProcess", "Account")) { %> <div> <fieldset> <legend>Hesap Bilgileri</legend> <div class="editor-label"> <%= Html.LabelFor(m => m.UserName) %> </div> <div class="editor-field"> <%= Html.TextBoxFor(m => m.UserName) %> <%= Html.ValidationMessageFor(m => m.UserName) %> </div> <div class="editor-label"> <%= Html.LabelFor(m => m.Password) %> </div> <div class="editor-field"> <%= Html.PasswordFor(m => m.Password) %> <%= Html.ValidationMessageFor(m => m.Password) %> </div> <div class="editor-label"> <%= Html.CheckBoxFor(m => m.RememberMe) %> <%= Html.LabelFor(m => m.RememberMe) %> </div> <p> <input type="submit" value="Giris" /> </p> </fieldset> </div> <% } %>

    Read the article

  • Why always fires OnFailure when return View() to Ajax Form ?

    - by Wahid Bitar
    I'm trying to make a log-in log-off with Ajax supported. I made some logic in my controller to sign the user in and then return simple partial containing welcome message and log-Off ActionLink my Action method looks like this : public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (MembershipService.ValidateUser(model.UserName, model.Password)) { FormsService.SignIn(model.UserName, model.RememberMe); if (Request.IsAjaxRequest()) { //HERE IS THE PROBLEM :( return View("LogedInForm"); } else { if (!String.IsNullOrEmpty(returnUrl)) return Redirect(returnUrl); else return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); if (Request.IsAjaxRequest()) { return Content("There were an error !"); } } } return View(model); } and I'm trying to return this simple partial : Welcome <b><%= Html.Encode(Model.UserName)%></b>! <%= Html.ActionLink("Log Off", "LogOff", "Account") %> and of-course the two partial are strongly-typed to LogOnModel. But if i returned View("PartialName") i always get OnFailure with status code 500. While if i returned Content("My Message") everything is going right. so please tell me why i always get this "StatusCode = 500" ??. where is the big mistake ??. By the way in my Site MasterPage i rendered partial to show long-on simple form this partial looks like this : <script type="text/javascript"> function ShowErrorMessage(ajaxContext) { var response = ajaxContext.get_response(); var statusCode = response.get_statusCode(); alert("Sorry, the request failed with status code " + statusCode); } function ShowSuccessMessage() { alert("Hey everything is OK!"); } </script> <div id="logedInDiv"> </div> <% using (Ajax.BeginForm("LogOn", "Account", new AjaxOptions { UpdateTargetId = "logedInDiv", InsertionMode = InsertionMode.Replace, OnSuccess = "ShowSuccessMessage", OnFailure = "ShowErrorMessage" })) { %> <%= Html.TextBoxFor(m => m.UserName)%> <%= Html.PasswordFor(m => m.Password)%> <%= Html.CheckBoxFor(m => m.RememberMe)%> <input type="submit" value="Log On" /> < <% } %>

    Read the article

  • Visual Studio 2013, ASP.NET MVC 5 Scaffolded Controls, and Bootstrap

    - by plitwin
    A few days ago, I created an ASP.NET MVC 5 project in the brand new Visual Studio 2013. I added some model classes and then proceeded to scaffold a controller class and views using the Entity Framework. Scaffolding Some Views Visual Studio 2013, by default, uses the Bootstrap 3 responsive CSS framework. Great; after all, we all want our web sites to be responsive and work well on mobile devices. Here’s an example of a scaffolded Create view as shown in Google Chrome browser   Looks pretty good. Okay, so let’s increase the width of the Title, Description, Address, and Date/Time textboxes. And decrease the width of the  State and MaxActors textbox controls. Can’t be that hard… Digging Into the Code Let’s take a look at the scaffolded Create.cshtml file. Here’s a snippet of code behind the Create view. Pretty simple stuff. @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>RandomAct</h4> <hr /> @Html.ValidationSummary(true) <div class="form-group"> @Html.LabelFor(model => model.Title, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Title) @Html.ValidationMessageFor(model => model.Title) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Description, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Description) @Html.ValidationMessageFor(model => model.Description) </div> </div> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } A little more digging and I discover that there are three CSS files of importance in how the page is rendered: boostrap.css (and its minimized cohort) and site.css as shown below.   The Root of the Problem And here’s the root of the problem which you’ll find the following CSS in Site.css: /* Set width on the form input elements since they're 100% wide by default */ input, select, textarea { max-width: 280px; } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Yes, Microsoft is for some reason setting the maximum width of all input, select, and textarea controls to 280 pixels. Not sure the motivation behind this, but until you change this or overrride this by assigning the form controls to some other CSS class, your controls will never be able to be wider than 280px. The Fix Okay, so here’s the deal: I hope to become very competent in all things Bootstrap in the near future, but I don’t think you should have to become a Bootstrap guru in order to modify some scaffolded control widths. And you don’t. Here is the solution I came up with: Find the aforementioned CSS code in SIte.css and change it to something more tenable. Such as: /* Set width on the form input elements since they're 100% wide by default */ input, select, textarea { max-width: 600px; } Because the @Html.EditorFor html helper doesn’t support the passing of HTML attributes, you will need to repalce any @Html.EditorFor() helpers with @Html.TextboxFor(), @Html.TextAreaFor, @Html.CheckBoxFor, etc. helpers, and then add a custom width attribute to each control you wish to modify. Thus, the earlier stretch of code might end up looking like this: @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Random Act</h4> <hr /> @Html.ValidationSummary(true) <div class="form-group"> @Html.LabelFor(model => model.Title, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.TextBoxFor(model => model.Title, new { style = "width: 400px" }) @Html.ValidationMessageFor(model => model.Title) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Description, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.TextAreaFor(model => model.Description, new { style = "width: 400px" }) @Html.ValidationMessageFor(model => model.Description) </div> </div> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } Resulting Form Here’s what the page looks like after the fix: Technorati Tags: ASP.NET MVC,ASP.NET MVC 5,Bootstrap

    Read the article

  • How to include the login form on the Home index page in MVC

    - by Bernard Larouche
    Hi guys I really need your help for this. I am relatively new to programming and I need help to something that could be easy for a experienced programmer. I would like to get the login form that we get for free in an MVC application on the left sidebar of my Home index page instead of the usual Account/Login page. I am facing some problems. First I need a product object to be displayed on my Home Index page as well. What I did is that I added a product object to the LogOnModel that they provide in the AccountModels class and I created a UserControl (partial view) copying the content of the LogOn.aspx view. Now my Home index.aspx as well as my partial view inherits the LogOnModel class. I can see the Login form on my Home Index page as well as my product object BUT the login Form is never empty. The last username and password always appear there. I know I must have forgotten something or have done something wrong or the way did it is completely wrong !! Please could you give me some advice Thks <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CoderForTradersSite.Models.LogOnModel>" %> <h4>Login Form</h4> <p> Please enter your username and password. <%= Html.ActionLink("Register", "Register") %> if you don't have an account. </p> <% using (Html.BeginForm()) { %> <%= Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.") %> <div> <fieldset> <legend>Account Information</legend> <div class="editor-label"> <%= Html.LabelFor(m => m.UserName) %> </div> <div class="editor-field"> <%= Html.TextBoxFor(m => m.UserName) %> <%= Html.ValidationMessageFor(m => m.UserName) %> </div> <div class="editor-label"> <%= Html.LabelFor(m => m.Password) %> </div> <div class="editor-field"> <%= Html.PasswordFor(m => m.Password) %> <%= Html.ValidationMessageFor(m => m.Password) %> </div> <div class="editor-label"> <%= Html.CheckBoxFor(m => m.RememberMe) %> <%= Html.LabelFor(m => m.RememberMe) %> </div> <p> <input type="submit" value="Log On" /> </p> </fieldset> </div> <% } %>

    Read the article

1 2  | Next Page >