asp.net mvc 4 - MVC 4, Model and model render differently -


i'm not sure why behavior, happy if pointing me right source, i'm not sure need google.

view model

public class generalday {     public byte tintweekday { get; set; }     public string nvardayname { get; set; }     public bool assigned { get; set; } } 

controller

    [childactiononly]     public partialviewresult targetday(models.viewmodels.promotion promotion) {          var daylist = gd.generaldaylist();         foreach (var day in daylist)         {              promotion.targetday.add(new models.viewmodels.generalday             {                 assigned = promotion.targetday.firstordefault(x => x.tintweekday == day.tintweekday) != null,                 nvardayname = day.nvardayname,                 tintweekday = day.tintweekday             });         }          modelstate.clear();         return partialview(promotion);     } 

view

@model generalday @using xxx.viewmodels;  <fieldset>    //first part  @(model.tintweekday) @(model.nvardayname) @(model.assigned)  //second part @html.labelfor(model => model.tintweekday)     @html.labelfor(model => model.nvardayname)     @html.labelfor(model => model.assigned)   </fieldset> 

the above display these result , why different result?

first part

1 sunday false

second part

tintweekday

nvardayname

assigned

because in first part render value of model properties.

@(model.tintweekday) renders 1 output.

but @html.labelfor(model => model.tintweekday) renders (nonexisting) label field, not value)

use displayattribute change field labels in model.

example:

public class generalday {     [display(description = "day of week")]     public byte tintweekday { get; set; }     public string nvardayname { get; set; }     public bool assigned { get; set; } } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -