Article View: alt.pl.comp.lang.csharp
Article #22259Re: ViewBag i ViewData na przemian (MVC3)
From: Łukasz 'Maly' Ostrowski
Date: Mon, 24 Oct 2011 07:19
Date: Mon, 24 Oct 2011 07:19
37 lines
2024 bytes
2024 bytes
On Sun, 23 Oct 2011 21:31:19 +0000, KO wrote:
> Dane wstawione do ViewData["Pole"] są dostępne Przez ViewBag.Pole
>
> Pytanie: czy można na tym polegać? Jest gdzieś zagwarantowane, że tak jest
> i będzie, czy to raczej jakiś efekt uboczny który może kiedyś zniknąć?
Można na tym polegać, ViewBag to Dynamic proxy do ViewData. Reflector
potwierdza ;-).
internal sealed class DynamicViewDataDictionary : DynamicObject
{
public override bool TryGetMember(GetMemberBinder binder,
out object result)
{
result = this.ViewData[binder.Name];
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
this.ViewData[binder.Name] = value;
return true;
}
<...>
}
Ale czy można polegać że w MVC 8 będzie tak samo, nie mogę się doszukać,
ale raczej nie spodziewałbym się zmian w tej materii.
Istotniejsze pytanie: po co w ogóle mieszać ViewData i ViewBag? Czy
mocno typowany Model nie jest wystarczający do 99% tasków? Z
doświadczenia zaobserwowałem że gołe ViewData/ViewBag służą z
reguły do hackowania ;-).
--
Pozdrawiam,
Łukasz 'Maly' Ostrowski. http://l3v.eu/
Technical Details
Message-ID:
<fhi69s30lz87.89en4ok06z7f$.dlg@40tude.net>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.dialog.net.pl!not-for-mailReferences:
<t9r8euypz3a5.128jw607exsbz$.dlg@40tude.net>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.dialog.net.pl!not-for-mail From: Łukasz 'Maly' Ostrowski <maly@USUNnemo.pl> Newsgroups: alt.pl.comp.lang.csharp Subject: Re: ViewBag i ViewData na przemian (MVC3) Date: Mon, 24 Oct 2011 09:19:05 +0200 Organization: Acme Lines: 37 Message-ID: <fhi69s30lz87.89en4ok06z7f$.dlg@40tude.net> References: <t9r8euypz3a5.128jw607exsbz$.dlg@40tude.net> NNTP-Posting-Host: static-78-9-71-129.ssp.dialog.net.pl Mime-Version: 1.0 X-Trace: news.dialog.net.pl 1319440766 5782 78.9.71.129 (24 Oct 2011 07:19:26 GMT) X-Complaints-To: abuse@dialog.net.pl NNTP-Posting-Date: Mon, 24 Oct 2011 07:19:26 +0000 (UTC) User-Agent: 40tude_Dialog/2.0.15.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit