c# - MVC Partial View and Models -



c# - MVC Partial View and Models -

i have homecontroller code:

public actionresult index() { indexmodel m = new indexmodel(); m.test = "somestring"; m.loginmodel = new viewloginmodel(); m.loginmodel.test = "fromlogin"; homecoming view("login", m); }

and in index.cshtml, have this:

@model indexmodel //bunch of html @html.partial("_login", model.loginmodel)

and in _login.cshtml, this:

@model viewloginmodel //bunch of html @html.labelfor(model => model.test)

basically, want have separate model partial window (login) in home page, , model can or not kid of viewindexmodel (ideally shouldn't exist). i'm trying access variables , write/use them in partial view, doesn't work - displays property's name instead.

in partial view "_login", intellisense doesn't work reason (vs2013), although @html.beginform , stuff working, can't access model's properties.

what doing wrong, how prepare this?

also, there difference between these two?

@html.partial("~/views/home/_login.cshtml") @html.partial("login")

it seems when i'm using #2 function "login" beingness called in homecontroller, not sure why...

the reason displaying property names because using html helper designed display property names.

@html.labelfor(model => model.test)

to output value of property in model, can utilize syntax

@model.test

if want able edit (assuming string), wrap in textboxfor helper

@html.textboxfor(model => model.test)

as sec question, assume without qualified name of view, routing engine getting involved. have not tested , typically utilize qualified name few milliseconds of speed .net not having seek , guess view asking for.

c# asp.net-mvc asp.net-mvc-4 razor

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -