mvc-editor-templates


MVC Editor Templates


I was trying nested Editor Templates but couldnt get it working. The structure of my model is
public class CompanyModel
{
public EmployeeModel Emp { get; set; }
}
public class EmployeeModel
{
public EmpType EmployeeType { get; set; }
public string Name { get; set; }
public DateTime StartDate { get; set; }
public string EmailAddress { get; set; }
}
public enum EmpType
{
Manager = 1,
Assistant = 2,
TeamLeader = 3
}
Each EmpType will have different EditorTemplates
The Index view is
#model CompanyModel
<h3>Index</h3>
#Html.EditorFor(m => m.Emp,"Employee")
Then i have create EditorTemplates(Employee.cshtml)
#model EmployeeModel
<h2>Employee</h2>
#Html.EditorForModel("EmpType_"+ Model.EmployeeType.ToString())
EditorTemplate(EmpType_Manager.cshtml)
#model EmployeeModel
<h2>EmpType_Manager</h2>
I am Manager
For testing i am populating the model with dummy data in the controller
public ActionResult Index(CompanyModel model)
{
EmployeeModel emp = new EmployeeModel
{
EmployeeType = EmpType.Manager,
Name = "xxxx",
StartDate = DateTime.Now,
EmailAddress = "xxx#yyy.com"
};
model = new CompanyModel();
model.Emp = emp;
return View(model);
}
When i run this it does not call the EmpType_Manager template. Can some one help me on this. I have tried using partial view which works. But would like to use EditorTemplate instead of Partial view.
Well looks like this is not possible as it is by mvc design.

Related Links

MVC Editor Templates

Categories

HOME
asp.net-web-api
scikit-learn
github-for-windows
pyqt
apache-spark-mllib
fftw
obfuscation
jwplayer
oracle-apex-5
static-site
alsa
rds
tail
echo
categorical-data
distribution
filechannel
onedrive-api
heat
bitnami
android-7.0-nougat
html5-appcache
connector
boost-icl
breadth-first-search
dapper-extensions
jquery-multiselect
jackson-modules
bioinformatics
carrierwave
uitapgesturerecognizer
xbox
deltaspike
rselenium
android-sugarorm
activexobject
openwhisk
joomla2.5
dm-script
linq-to-objects
preloader
oracle-service-bus
wcftestclient
hammer.js
remedy
page-replacement
mathcad
cronexpression
builtins
redistributable
envi
rspec2
gogs
shopping
cassia
hadoop-partitioning
turbo-prolog
kiosk
phpwebsocket
upx
ellucian-scribe
nullable
aspen
false-sharing
rasterize
xenomai
binomial-theorem
text-search
iced-coffeescript
amiga
pyobjc
google-refine
android-cookiemanager
sonarqube-5.0
spy++
unix-socket
mutual-authentication
android-framework
gwt-openlayers
scrypt
nevron
cross-database
jquery-tools
promotion-code
landscape-portrait
matlab-load
fsevents
u2netdk
inline-formset
socketserver
build-environment
tui
mathematical-notation
application-planning
java1.4
wcf-proxy

Resources

Encrypt Message