Aug 04, 2014, 6:57 PM
[CLOSED] Custom Control or User Control in razor MVC
I found a forum post http://forums.ext.net/showthread.php...ustom-controls
but I need to build a control using 2-3 other controls how do I do this?like a NumberField,DisplayField and a combobox
I tried to do this with partial view .
MODEL
Please let me know how to do this properly
but I need to build a control using 2-3 other controls how do I do this?like a NumberField,DisplayField and a combobox
I tried to do this with partial view .
MODEL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ext.Net;
using Ext.Net.MVC;
namespace e.Models
{
public class time
{
public string HH
{
get { return X.GetCmp<NumberField>("hh").Value.ToString(); }
set { X.GetCmp<NumberField>("hh").Value = value; }
}
public string MM
{
get { return X.GetCmp<NumberField>("mm").Value.ToString(); }
set { X.GetCmp<NumberField>("mm").Value = value; }
}
public string TT
{
get { return X.GetCmp<ComboBox>("tt").Value.ToString(); }
set { X.GetCmp<ComboBox>("tt").Value = value; }
}
public string returntime()
{
string strRes = string.Empty;
string strHH = string.Empty;
string strMM = string.Empty;
string strTT = string.Empty;
strHH = HH;
strMM = MM;
strTT = TT;
if (strHH.Length < 2)
{
strHH = "0" + strHH;
}
if (strMM.Length < 2)
{
strMM = "0" + strMM;
}
strRes = strHH + ":" + strMM + " " + strTT;
return strRes;
}
public time settime(string strtime)
{
string[] str1st = strtime.Split(':');
string[] str2nd = str1st[1].Split(' ');
time _time = new time();
_time.HH = str1st[0];
_time.MM = str2nd[0];
_time.TT = str2nd[1];
return _time;
}
}
}
PARTIAL VIEW@using Ext.Net
@using Ext.Net.MVC
@{
var X = Html.X();
}
<script>
var hhValidation = function () {
if (Ext.getCmp("hh").getValue() > 12) {
Ext.getCmp("hh").setValue(12);
}
// alert("HI")
}
var mmValidation = function () {
if (Ext.getCmp("mm").getValue() > 59) {
Ext.getCmp("mm").setValue(59);
}
// alert("HI")
}
</script>
@(X.Container().LayoutConfig(new HBoxLayoutConfig { Align = HBoxAlign.StretchMax }).Border(false).Width(200).Padding(10)
.Items
(
X.NumberField().ID("hh").Width(22).LabelWidth(20).MaxLength(2).Text("09")
.AllowBlank(false).HideLabel(true).HideTrigger(true).MaxValue(12)
.Listeners(l => { l.Change.Fn = "hhValidation"; }),
X.DisplayField().Text(":"),
X.NumberField().ID("mm").Width(22).LabelWidth(20).MaxLength(2).Text("30")
.AllowBlank(false).AllowDecimals(false).MaxValue(59)
.Listeners(l => { l.Change.Fn = "mmValidation"; })
.HideTrigger(true),
X.DisplayField().Text(":"),
X.ComboBox().ID("tt").Width(45).LabelWidth(20).HideLabel(true).Editable(false).AllowBlank(false)
.SelectedItems("AM")
.Items(
new ListItem { Text = "AM" },
new ListItem { Text = "PM" }
)
)
)
VIEW@using Ext.Net
@using Ext.Net.MVC
@{
Layout = null;
var X = Html.X();
}
<script>
var validation = function () {
if (Ext.getCmp("f").isValid() == true) {
return true;
}
else {
return false;
}
}
</script>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@X.ResourceManager()
@(X.FormPanel().Border(false).ButtonAlign(Alignment.Left).ID("f")
.Items(
X.Container()
.ItemsFromPartial("~/Views/Shared/_Partial.cshtml"),
X.Container()
.ItemsFromPartial("~/Views/Shared/_Partial.cshtml")
)
.Buttons
(
X.Button().DirectClickAction("test")
.Listeners(l => { l.Click.Handler = "return validation()"; })
)
)
</div>
</body>
</html>
CONTROLLERusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ext.Net;
using Ext.Net.MVC;
using e.Models;
namespace e.Controllers
{
public class ucController : Controller
{
//
// GET: /uc/
e.Models.time _time = new time();
public ActionResult Index()
{
_time.settime("10:35 PM");
return View();
}
public DirectResult test()
{
string s = _time.returntime();
return this.Direct();
}
}
}
but its through an error,because I use the same partial view more then one in a view and id conflict ,but I need to use the same partial view more then one in a view.without set any ID to fields its works fine,but I for setting value dynamically I have to set ID.please see Model code.
A Control with an ID of "App.hh" has already been initialized. Please ensure that all Controls have a unique id.
The following Control has the same ID as at least one other Control on the Page. All Controls must have a unique ID.
The following Control has the same ID as at least one other Control on the Page. All Controls must have a unique ID.
Please let me know how to do this properly
Last edited by Daniil; Aug 08, 2014 at 9:35 AM.
Reason: [CLOSED]