Solved

Bootstrap button not showing as selected on post back.

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now