MVC :: Handle Strongly Typed Views If Have Multiple Objects/models?

Mar 16, 2011

<p>Hi</p> <p>I'm a newbie in MVC but a veteran web forms developer. I really like the idea of strongly typed views but what if I have multiple objects to pass to my razor view. Would I then NOT use strongly typed views and just use the ViewBag?</p>

View 3 Replies

Similar Messages:

MVC Strongly Typed Versus Dynamically Typed Views

Nov 25, 2010

Given the benefits of using strongly typed views to eliminate typed errors and the use of lambda expressions why would one use a dynamically typed view? When I use them I don't feel as safe as with strongly typed views. Am I missing something? Is there a special use for them?

View 2 Replies

MVC :: Strongly Typed HtmlHelpers And View Models?

Oct 26, 2010

I am not sure why this happens, but when I have an Html.TextBoxFor(model => model.SomeObject.SomeProperty), when I post, the property of that object is always null.

When I look at the markup generated, I see <input type="text" name="SomeObject_SomeProperty" id="SomeObject.SomeProperty" value = "" />

If I change the helper to Html.TextBoxFor(model => model.SomeObject.SomeProperty, new {id = "SomeProperty"}) the controller is then able to pick the value up. Why is this happening? I feel as though I shouldn't have to be specifiying the id for the textbox as it works when fine when not using child objects on a view model, IE <%: HtmlTextBoxFor(model => model.SomeProperty) %>.

View 8 Replies

MVC :: Strongly Typed Views: Only One Object Allowed?

May 11, 2010

Just a quick question really but with the strongly typed views where MVC can autobind form fields to the propertys of an object I define, how does this work when supporting multiple forms on the same view?Is it possible to have two objects with different properties,

Object1 { Name, Age }
Object2 { StartDate, EndDate }

Then on the view have two seperate forms, one for each object and the controller can work out which object it is to post back because of the form which eventually gets posted back?

View 5 Replies

Sharp Architecture Question - No Strongly Typed Views?

Mar 24, 2010

I am trying to get my head around the sharp architecture and used the visual studio template as described on the web:[URL] This is all cool. Unfortunately, I cannot add a strongly typed view as easily as I am used to 'under' mvc.

What can I do to 'enable' this in VS 2008 Prof? I have also installed mvc 2.0 and would like to reflect this in my 'vs studio sharp environment'.

View 1 Replies

MVC :: Best Practice To Have Multiple Strongly Type Models Inside A Single View?

Oct 26, 2010

So far I've seen demos of MVC that have simple pages, one for login, one for register, one for listing a table. In order to understand better the transition for WebForms developers into MVC patterns, I would like to understand how can I put together multiple CONTROLS (like the one provided by the default MVC project that VS2010 creates for us ...and make it work. OK so as an example, imagine we want to change the LogonUserControl.ascx to allow us to login (so to show UserName and Password textboxes and Logon button) from the Home Page.

1) We update the Control as follow:

2) We update the HomeController.cs file to handle the Logon Button Post event as follow:

We needed to move some code from AccountController to HomeController in order to get the control to work under the Index view. So ...with little luck it seems to work! Now the problem happens when you navigate to the Register view, considering that now we are not any longer on the HomeController "domain" but we are under AccountController. Register page shows perfectly and since the LogOnUserControl.ascx belongs to the MasterPage, it shows too. Since we are not logged yet, it will be displaying the UserName and Password textboxes. But we don't really care about that, because we are on the Register view and after populating the Register values, we click on the Register button. This is the error I get:

>>> To me that I come from the WebForms world, it seems like even if the event fired was the Register button (therefore under the AccountController domain), there is a kind of hidden OnInit event fired for any control on that view, in this case the Logon event. I'm sure this is NOT the case but the real question is... if we are allowed to have only one Controller x view, how can we put together controls that come from different "controller domains" and display them inside a single view?

Could I develop an eCommerce site using MVC that has the home page displaying different controls like [Most Purchased Product, Product of the Month, Special Promotions, Messages Inbox, Company Events ... and each control has it's own button to click and do something (so a proper POST request)] on the home page, unless I only have ONE single Controller which i'm not even sure if it will work or if it would make sense ....since MVC is all about separation of responsibilities.

View 7 Replies

ADO.NET :: Generate Strongly Typed Datatables From Multiple Result Set Proc?

Nov 23, 2010

For a reporting stored procedure that returns multiple result sets that don't map to

any database tables, I'm able to use SqlConnection(), fill a DataSet, and name the

different tables uniquely (as opposed to the default Table, Table1, Table2).

However, I want to make the returned DataTables to be strongly typed.

There's plenty of articles out there about strongly typed DataSets, etc.,

View 2 Replies

MVC :: Handle Multiple Models In A View?

Aug 11, 2010

How do you handle multiple models in a view?. I have 2 tables. Member and MemberAddress

Member class contains Collection of MemberAddresses since a single member may have a billing and shipping address:

public class Member
public virtual int MemberId { get; set; }
public virtual string Username { get; set; }
public virtual bool IsActive { get; set; }
public virtual bool IsSame { get; set; }


View 3 Replies

Strongly-typed Or Weakly-typed Binding In Codebehind In Front End?

Feb 23, 2010

So my question is more in relation to what people consider to be the best practice and why:

I've been dropping literals into pages and repeaters and binding them in code behind for a while. Is this considered bad practice?


ASPX Page:

<asp: Literal id="litTextToInsert" runat="Server" />

Code Behind:

litTextToInsert.Text = objData.MyText;

OR (repeater):


I personally dont like doing this as i find it makes it harder for me to know if someone changed the field name, or mis typed it during development - the other way you won't know until the page loads.

With the strongly typed version if something changes in your DAL etc the build will break - letting me know I've messed up.

Why do so many people appear to use weakly typed code in ASP.Net (in examples, MVC, etc)?
Am i missing something?

View 2 Replies

Caching - What Techniques Should Be Used To Handle Objects In Cache To Prevent Problems From Multiple Worker Threads Access

Sep 8, 2010

since contains multiple threads that are executing at the same if 2 threads access an object (simple or complex) that i got from the the httpcontext Cache.can't this lead to state problems on that object if these 2 theads tried to modify/read it at the same time?so what kind of precautions should i implement?for example i am thinking maybe locking the object while working with it? (wont this cause performance problems?)or maybe when i retrieve some object from the cache i should create a copy from it?
or maybe i dont need to worry about this issue at all?

View 2 Replies

Mvc - Get Strongly Typed From String

Jan 18, 2010

My error code:

string model = "Content";
Type stype = Type.GetType("mvc.Models." + model);
ViewPage<stype> vp = new ViewPage<stype>();

Of course it error when compiling, but it clearly show what i'm thinking.

View 1 Replies

Is There A Strongly Typed RedirectToAction In MVC 2

Oct 2, 2010

I wish to do something like this:

return RedirectToAction<SomeController>(c => Index(someparameter));

How to do this ?

View 2 Replies

MVC :: Do Have Strongly-typed Redirects Yet

Dec 10, 2010

Been using MvcContrib for strongly typed redirects since MVC1. Aren't we there yet with MVC3 or did I miss something (just been scratching the surface)

View 5 Replies

.NET MVC - Models Notifying The Views?

Dec 1, 2010

In some of the classic descriptions of MVC, the Model notifies Views via the observer pattern. It seems to me that this doesn't happen with ASP.NET MVC, and so one of the fundamental relationships between Model, View, and Controller is missing.

Is this the case? If so, why?

View 2 Replies

MVC :: Different Models In Partial Views

Nov 17, 2010

I have following architecture. My Model:


The partial view "PersonsView" has the same model and looks like this:<%@ Control Language="C#"

Inherits="System.Web.Mvc.ViewUserControl<Web.Models.WebModel>" %><%Html.RenderPartial("Person", Model.Persons.First); %><%Html.RenderPartial("Person", Model.Persons.Second); %>

And the the partial view "Person" has an other model:[Code].... If I press the "Submit-Button" on the first view I get to the follwing controler: [Code]....

View 2 Replies

MVC :: Using A Partial In A Strongly Typed View?

Oct 4, 2010

I have an application that is going to allow a user to create records of type Customer and Seller that have one section in common, but other fields that are unique to their types.

Both of these types will have an address block for their create view.

If I have a strongly typed Customer or Seller view, how can I use the view partial (containing the address block) that I've created? I've tried creating a view model, but I don't know how to have the create page inherit the Customer model and the addressBlock partial inherit the addressBlockForm partial model...

View 7 Replies

MVC :: 2 Strongly Typed Html Helpers Css?

Jul 28, 2010

How can I use css and other attributes such max length with the strongly typed views ?

View 1 Replies

MVC :: @Html.Label Strongly Typed?

Dec 10, 2010

I want strongly typed Label but not working at all. Can you fix the below use of Label to display like @Html.Label("FirstName"). MVC3 Razor.

View 4 Replies

C# - What Exactly Is Strongly Typed View Data In MVC

Feb 2, 2010

What is meant by "strongly typed view data" in Asp.Net MVC ?

View 3 Replies

C# - MVC Strongly Typed View With DropDownList

Jul 6, 2010

Long story short, I'm trying to add a few extra items to ViewData to make my life easier, and its an edge case that doesn't really justify its own model just for this one case. Keep reading for more specific details.

So I have a strongly typed edit view for one of my objects, everything works great until I try to put a dropdownlist on the view with an ID that does not match a property of my class.

I have this


My expectation is that in the controller action that accepts the POST, I will manually use the FormCollection[] to read out that ID and populate MyOtherModel with the correct ID.

View 1 Replies

MVC :: View Strongly Typed With (PagedList Of Xxx)?

Jul 3, 2010

all i have this problem


MVC :: View strongly typed with (PagedList of xxx?

View 3 Replies

Strongly Typed API For MVC 2 Async Actions

May 17, 2010

Have anybody tried to create strongly typed API for ASP.NET MVC 2 async actions?

View 1 Replies

Strongly Typed - How Much Time To Compile A View

Oct 1, 2010

How much time is spent compiling a view in ASP.NET?Of course I don't expect anyone to give me a number, but I think it's interesting to have an idea of how much time this takes because it could influence the way we implement things.For example, if the time is significant , then I might try to put every result that I need to display in the view in a model class instance (created just to hold the values in such a way that I don't even have to test for objects with null value) and then minimize to the maximum (uh?) the amount of C# code in the view thus decreasing the amount of time necessary to compile the view.Question Does this make sense? Give some thoughts on this one.

View 1 Replies

Returning A Single Row In A Strongly Typed DataSet In C#?

Jun 27, 2010

I have a Strongly typed Dataset TableAdapter in C#, how do I get a single row from it?

View 4 Replies

Bulk Update Strongly Typed Dataset?

Mar 7, 2011

is it possible to do a batch update in a strongly typed data set? UpdateBatchSize does not seem to be an option once you create a strongly typed dataset.

View 1 Replies

Copyrights 2005-15, All rights reserved