asp.net mvc - I have second Model I am trying to fill in a View and return. MVC 5 -
i start in controller
viewbag.emailstuff = new emailstuff();
then in view, try model because view based on different one.
@{var es = viewbag.emailstuff emailstuff;} @using (html.beginform("contactstore", "store", formmethod.post, new {emailstuff=es))
and have validaton working these 2 fields, fires if empty
@html.editorfor(m => es.eventname) @html.validationmessagefor(m => es.eventname, "", new { @class = "text-danger-yellow" }) <br /> @html.editorfor(m => es.messagebody) @html.validationmessagefor(m => es.messagebody, "", new { @class = "text-danger-yellow" })
but can't figure out how values controller if fields have info in them.
at controller, model referencing returns nulls both inputs though dataannotations works.
i know hack. i'm trying away forms collection , learn how use models. view using different model 1 trying validate. @ top of view can see different model has nothing 2 fields sending emailer.
@model stores.models.vprofiles @using microsoft.aspnet.identity @using microsoft.aspnet.identity.entityframework @using stores.models
here info supposed coming in:
public actionresult contactstore(emailstuff emailstuff) {
here model:
public class emailstuff { [required(errormessage = "enter event name")] public string eventname { get; set; } [required(errormessage = "you need enter message")] public string messagebody { get; set; } } }
i'll burned in hell spaghetti, i'm hoping there easy solution missing (besides glueing several views together).
just @stephen said return same model view like;
var emailstuff = new emailstuff(); emailstuff = viewbag.emailstuff; return view(emailstuff);
and in view use this.
@html.editorfor(m => m.eventname) @html.validationmessagefor(m => m.eventname, "", new { @class = "text-danger-yellow" })
after should getting data want @ controller side when post form.
Comments
Post a Comment