Solved

Bootstrap button not showing as selected on post back.

Posted on 2015-02-05
2
376 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

632 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