Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Bootstrap button not showing as selected on post back.

Posted on 2015-02-05
2
Medium Priority
?
424 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

876 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