Solved

Bootstrap button not showing as selected on post back.

Posted on 2015-02-05
2
363 Views
Last Modified: 2016-02-25
When my model comes back is not valid and the page reloads my radio button  that is selected does not visually show as selected. What can I do to correct this problem?

  <div id="radios">
            <div class="form-group">
                <div class="btn-group col-md-offset-1" data-toggle="buttons">
                    <label class="btn btn-default btn-lg col-md-1">
                        @Html.RadioButtonFor(model => model.SetDollarAmount, "25", new { id = "Amount25" }) $25
                    </label>
                    <label class="btn btn-default btn-lg col-md-1">
                        @Html.RadioButtonFor(model => model.SetDollarAmount, "50", new { id = "Amount50" }) $50
                    </label>
                    <label class="btn btn-default btn-lg col-md-1">
                        @Html.RadioButtonFor(model => model.SetDollarAmount, "100", new { id = "Amount100" }) $100
                    </label>
                    <label class="btn btn-default btn-lg col-md-1">
                        @Html.RadioButtonFor(model => model.SetDollarAmount, "250", new { id = "Amount250" }) $250
                    </label>
                    @Html.LabelFor(model => model.Amount, new { @class = "control-label col-md-4" })
                    <div class="col-md-2">
                        @Html.TextBoxFor(model => model.Amount, new { @class = "form-control input-large" })
                        @Html.ValidationMessageFor(model => model.Amount)
                    </div>
                </div>
            </div>
        </div>

Open in new window

0
Comment
Question by:NickMalloy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 5

Accepted Solution

by:
kblau earned 500 total points
ID: 40677082
This works fine:
[HttpPost]
        public ActionResult Index(EEBootstrap.Bootstrap item)
        {
            ePIPDAPEntities entity = new ePIPDAPEntities();
            var query = entity.Bootstraps.FirstOrDefault();
            query.SetDollarAmount = item.SetDollarAmount;
            if (!ModelState.IsValid) {
           
                entity.SaveChanges();
            }
            return View(db.Bootstraps.FirstOrDefault());
        }

-------------
//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace EEBootstrap
{
    using System;
    using System.Collections.Generic;
   
    public partial class Bootstrap
    {
        public int id { get; set; }
        public Nullable<int> SetDollarAmount { get; set; }
        public Nullable<int> Amount { get; set; }
    }
}
------------------
//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace EEBootstrap
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
   
    public partial class ePIPDAPEntities : DbContext
    {
        public ePIPDAPEntities()
            : base("name=ePIPDAPEntities")
        {
        }
   
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }
   
        public DbSet<Bootstrap> Bootstraps { get; set; }
    }
}

---------------
@model EEBootstrap.Bootstrap

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>

@using (Html.BeginForm()) {

<div id="radios">
            <div class="form-group">
                <div class="btn-group col-md-offset-1" data-toggle="buttons">
                    <label class="btn btn-default btn-lg col-md-1">
                        @Html.RadioButtonFor(model => model.SetDollarAmount, "25", new { id = "Amount25" }) $25
                    </label>
                    <label class="btn btn-default btn-lg col-md-1">
                        @Html.RadioButtonFor(model => model.SetDollarAmount, "50", new { id = "Amount50" }) $50
                    </label>
                    <label class="btn btn-default btn-lg col-md-1">
                        @Html.RadioButtonFor(model => model.SetDollarAmount, "100", new { id = "Amount100" }) $100
                    </label>
                    <label class="btn btn-default btn-lg col-md-1">
                        @Html.RadioButtonFor(model => model.SetDollarAmount, "250", new { id = "Amount250" }) $250
                    </label>
                    @Html.LabelFor(model => model.Amount, new { @class = "control-label col-md-4" })
                    <div class="col-md-2">
                        @Html.TextBoxFor(model => model.Amount, new { @class = "form-control input-large" })
                        @Html.ValidationMessageFor(model => model.Amount)
                    </div>
                </div>
            </div>
        </div>

    <input type="submit" id="btnAP" value="submit" />
}
0
 
LVL 5

Expert Comment

by:kblau
ID: 40677083
Oh, I will do this with bootstrap next...
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
looking for an ASP.net report designer 4 51
Query in AngularJS 8 83
Aspx calendar pop up control 3 38
Broken .resx file generating errors 18 44
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question