PDA

View Full Version : [CLOSED] MVC3 Editor Template



adelaney
May 03, 2012, 8:41 PM
I am trying to create an editor template and need a little help. Here is my code:


@modelType Models.LookUp

@code
If Model IsNot Nothing Then
Html.X.ComboBox().ValueField("DataValueField").DisplayField("DataTextField") _
.QueryMode(DataLoadMode.Local) _
.Store(Sub(action)
action.Add(Html.X.Store().DataSource(Model.Options ) _
.Model(Sub(mdl)
mdl.Add(Html.X.Model().Fields(Sub(flds)
flds.Add("DataTextField")
flds.Add("DataValueField")
End Sub))
End Sub))
End Sub) _
.ID(ViewData.ModelMetadata.PropertyName) _
.Listeners(Sub(action)
action.TriggerClick().AddScript("this.clearValue();")
End Sub) _
.Triggers(Sub(trg)
trg.Add(Html.X.FieldTrigger().Icon(TriggerIcon.Cle ar).Qtip("Clear Selection"))
End Sub).Render()
End If
End Code

I am receiving an error "Error executing child request for handler 'Ext.Net.SelfRenderingPage'." Is there another way that I shold go about creating an editor template with your controls?

Daniil
May 03, 2012, 10:29 PM
Hi,

I'm not the best in VB Razor syntax, but I was able to get the following working.

Example View

@Html.X().ResourceManager()
@code
If Model IsNot Nothing Then
Dim comboBox = Html.X().ComboBox().ValueField("DataValueField").DisplayField("DataTextField") _
.QueryMode(DataLoadMode.Local) _
.Store(Sub(action)
action.Add(Html.X.Store().DataSource(Model) _
.Model(Sub(mdl)
mdl.Add(Html.X.Model().Fields(Sub(flds)
flds.Add("DataTextField")
flds.Add("DataValueField")
End Sub))
End Sub))
End Sub) _
.ID(ViewData.ModelMetadata.PropertyName) _
.Listeners(Sub(action)
action.TriggerClick.Handler = "this.clearValue();"
End Sub) _
.Triggers(Sub(trg)
trg.Add(Html.X.FieldTrigger().Icon(TriggerIcon.Cle ar).Qtip("Clear Selection"))
End Sub)
@comboBox
End If
End Code


Example Controller Action

public ActionResult TestRazor()
{
return View(new List<object>()
{
new
{
DataTextField = "text 1",
DataValueField = "value 1"
},
new
{
DataTextField = "text 2",
DataValueField = "value 2"
},
});
}