asp.net mvc - Understanding how strongly typed html helper works -
framework: asp.net mvc 3
tools: vs 2012
hi guys, i'm new asp.net mvc, have been using typed html helper time,i don't understand them know can provide type checking , keeps name according property name,after using many times faced error , dont seem have hint why occuring tried several google searches none helped me.
error: name 'm' not exist in current context
code: @html.labelfor(m => m.orginalcont.title)
but line of code works fine. @html.textbox("origtitle", model.orginalcont.title, new { @readonly = "", @class = "text-rounded", style = "width:425px" })
can tell me whats going on here.i have used same m => m.name
syntax several times in view working fine.
update: alright try post more code,but code may long try keep short , post code related problem.
view
@model ts.mop.interface.models.projecttranslationmodel <div class="form-item"> @html.labelfor(model => model.orginalcont.title) <div class="editor-field"> @html.textbox("origtitle", model.orginalcont.title, new { @readonly = "", @class = "text-rounded", style = "width:425px" }) </div> </div>
model
public class projecttranslationmodel { public int projectid { get; set; } [required(errormessageresourcetype = typeof(names), errormessageresourcename = "required_errormessage")] [datatype(datatype.text)] [display(resourcetype = typeof(names), description = "translatelangs_description", name = "translatelangs_title")] public list<selectlistitem> translatablelangselect { get; set; } public translatablelanguageeditor translatablelangeditor { get; set; } public originalcontent orginalcont { get; set; } }
controller
[authorize] public actionresult translationedit(int? id) { if (id.hasvalue && user.isinrole("contenttranslator")) { var model = new projecttranslationmodel(); model.projectid = id.value; var contenttypeid = 2;//project page guid _currentuserid = guid.parse(membership.getuser(user.identity.name).provideruserkey.tostring()); var translatorsettings = db.translatorsettings.where(x => x.userid == _currentuserid).tolist(); model.translatablelangeditor = new translatablelanguageeditor(); var list = new list<selectlistitem>(); //original text var originalcontent = db.projects.where(x => x.id == id.value) .select(d => new originalcontent { title = d.title, content = d.description, contentcultureid = d.projecttype.contentcultureid }).firstordefault(); model.orginalcont = originalcontent; foreach (var item in translatorsettings) { //select list var li = new selectlistitem(); if (item.contentcultureid != originalcontent.contentcultureid)//dont add original content cultureid dropdown { li.value = item.contentcultureid.tostring(); li.text = item.contentculture.description; list.add(li); } } model.translatablelangselect = list; return view(model); } else { return view("index"); } }
Comments
Post a Comment