PDA

View Full Version : [CLOSED] RadioFor always False



matrixwebtech
Sep 25, 2014, 6:16 PM
I set up 3 radio buttons but never get true value for selected radio,please help.

View


@model ERP_test.Controllers.radiogroup
@{
var X=Html.X();
}
@X.ResourceManager()

@(X.FormPanel().ID("f")
.Items
(

X.FieldContainer().AnchorHorizontal("100%").Layout(LayoutType.HBox)
.Items
(



X.RadioFor(obj => obj.radio1)
.Name("PF")
,
X.RadioFor(obj => obj.radio2)
.Name("PF")
,
X.RadioFor(obj => obj.radio3)
.Name("PF")

)



)
.Buttons
(

X.Button()
.Text("Save")
.ID("btnSave")


.DirectEvents(de =>
{

de.Click.FormID = "f";
de.Click.Action = "save";

})

)
)

Controller

public class RadioForController : Controller
{
//
// GET: /RadioFor/

public ActionResult Index()
{
return View();
}
public void save(radiogroup _radiogroup)
{

}

}
public class radiogroup
{
public bool radio1 { get; set; }
public bool radio2 { get; set; }
public bool radio3 { get; set; }
}

Daniil
Sep 26, 2014, 9:52 AM
Hi @matrixwebtech,

You should use a ModelBinder.
http://forums.ext.net/showthread.php?24049&p=105622&viewfull=1#post105622

matrixwebtech
Sep 26, 2014, 11:21 AM
Hi,
I am not clear what I have to do exactly for radio button,but I found if I remove

.Name("PF")
and code like bellow


X.RadioFor(obj => obj.radio1)
.Listeners(l =>
{
l.Change.Handler = @"if(this.getValue()==true)
App.radio2.setValue(false);
App.radio3.setValue(false);
";
})


,
X.RadioFor(obj => obj.radio2)
.Listeners(l =>
{
l.Change.Handler = @"if(this.getValue()==true)
App.radio1.setValue(false);
App.radio3.setValue(false);
";
})

,
X.RadioFor(obj => obj.radio3)
.Listeners(l =>
{
l.Change.Handler = @"if(this.getValue()==true)
App.radio1.setValue(false);
App.radio2.setValue(false);
";

})

Its works,but I face a problem,some time I have to click twice to select a radio,most of time for radio3
property then its working fine .any suggestion

Daniil
Sep 27, 2014, 7:49 AM
I guess the problem is that the Change event probably fires on each .setValue() call.

Well, I would not recommend you to organize a radio group in this way. I think your initial solution is better.