PDA

View Full Version : [CLOSED] MVC - how to exclude form field at runtime



aguidali
Nov 08, 2013, 9:42 AM
Hi guys,

I have a Window with inside a FormPanel; the panel contains two textfield; I was wondering how can I exclude at runtime the second textfield using a parameter contained in the model.

Seems simple but i Cannot find the correct sintax!

More generally the question would be: how can I insert code snippet ( @if(Model.parameter == 0) ... ) inside the Window definition?

Any suggestion is really appreciated!

Thanks


Html.X().Window()
.ID("FormId")
.Title("FormTitle")
.Width(windowWidth)
.Height(580)
.Layout(LayoutType.Fit)
.Closable(false)
.Border(false)
.Hidden(true)
.Resizable(false)
.Modal(true)
.Items(
Html.X().FormPanel()
.Url(Url.Action("Submit","Firm"))
.ID("FormPanelId")
.MarginSpec("0 0 0 0")
.Layout(LayoutType.VBox)
.BodyPadding(5)
.Defaults(Html.X().Parameter().Name("margins").Value("0 5 0 0").Mode(ParameterMode.Value))
.LayoutConfig(new VBoxLayoutConfig { Align = VBoxAlign.Left })
.Items(
Html.X().TextField()
.FieldLabel("Name")
.ID("Id1")
.Width(componentWidth)
.LabelWidth(labelWidth)
.Margins("5 10 0 0")
.ReadOnly(true),

Html.X().TextField()
.FieldLabel("Surname")
.ID("Id2")
.Width(componentWidth)
.LabelWidth(labelWidth)
.Margins("5 10 0 0")
.ReadOnly(true)))

Daniil
Nov 08, 2013, 11:34 AM
Hi @aguidali,

Welcome to the Ext.NET forums!

It is easier not to add a TextField rather than excluding.

Example

@{
var X = Html.X();
}

<!DOCTYPE html>
<html>
<head>
<title>Ext.Net.MVC v2 Example</title>
</head>
<body>
@X.ResourceManager()

@(X.FormPanel()
.Items(items =>
{
items.Add(new TextField() { FieldLabel = "TextField 1" });

if (Model.AddSecondTextField)
{
items.Add(new TextField() { FieldLabel = "TextField 2" });
}
})
)
</body>
</html>

aguidali
Nov 08, 2013, 11:50 AM
Ok,

Thanks Daniil !!