.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Using a partial in a strongly typed view

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :ASP.Net

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...

Hopefully, this makes sense, and thank you for any help.

View Complete Post

More Related Resource Links

binding dictionary with strongly typed view

hey guys ,i m beginner in asp.net mvc , i have strongly typed view and i m passing my dictionary in view as :Dictionary<Guid,IYummyWebAppMVC.Models.Restaurant.Menu>>" %> Dictionary<Guid , MyApp.Models.Res.Menu>  how do i access this in html ?how do i iterate thru it and get value of both the items ?

strongly typed view - Complex Model

I have a class ProjectDetailModelView with       ProjctDetail (fields to display)        UserList - SelectList (for dropdown control)I pass in  Inherits="System.Web.Mvc.ViewPage<glossaryDB.Manager.ProjectDetailModelView>" %>       And I want to use something like the following:<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">    <h2>Project : Edit</h2>     <% Html.EnableClientValidation(); %>    <% using (Html.BeginForm()) { %>        <fieldset style="padding: 1em; margin: 0; border: solid 1px #999;">            <%= Html.ValidationSummary("Broken stuff:") %>               <%= Html.EditorForModel() %>            <input type="submit" value="  Submit  " />   

Strongly typed view validation


I have a strongly typed view with my model being entity framework.  In my controller I check for ModelState.IsValid.  When I submit my form without a value for a column that does not allow nulls it crashes before it gets to the ModelState.IsValid line and the error is about not allowing nulls in the column.  Shouldn't this be what is handled by the ModelState.IsValid line?  I feel like I am missing something obvious. 

Strongly typed view and viewModel


Hello together,

I have a question about strongly typed views.

I already have my business objects (based on the persistence framework xpo form dev express). These objects have some associations.

eg. an article can have some user comments


My question now is, should my strongly typed views directly base on this objects (even if these objects have many properties i never need to present)

or should i create additional classes containing only the properties of the objects which i like to present.

eg. articleViewModel and commentViewModel.

where a articleViewModel can have associations with multiple commentViewModel

The advantage which i see in the second example is, that i can easier validate the viewModels.

However it means a lot of extra work, because i need to create for all objects which i like to present a viewModel with the corresponding

associations and properties.

Thanks a lot!

Regards Vincenzo

MVC2: Change the default generated HTML when creating a strongly typed view


Is there any way to change the HTML that is generated by default when you create a strongly typed view in MVC2?

I currently get a structure like this:

            <div class="editor-label">
                <%: Html.LabelFor(model => model.category_id) %>
            <div class="editor-field">
                <%: Html.TextBoxFor(model => model.category_id) %>
                <%: Html.ValidationMessageFor(model => model.category_id) %>

I want to change it to a structure like this:

                <div><%: Html.ValidationMessageFor(model => model.user_login) %></div>
                <div><%: Html.LabelFor(model => model.user_login) %></div>
                <div><%: Html.TextBoxFor(model => model.user_login) %></div>

Strongly Typed HtmlHelpers and View Models



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) %>.

Upload with strongly-typed view - Create Method



How to can upload a file to database with strongly typed view - create method?

Picture is a binary db column

<%: Html.TextBoxFor(Function(model) model.Resim)%>


 How i can translate "TextBoxFor" to "UploadFileFor"?

Downcasting to base class Strongly typed view


I have the following entity object:

    public class ForumPost
            public virtual int ForumPostId { get; set; }
            public virtual int LoginId { get; set; }
            public virtual string Body { get; set; }

Then I have page that would has a list of ForumPost(s) and and edit option, all on one page. To achieve this I've created a CommentsViewModel that extends "ForumPost" class like so:

    public class CommentsViewModel : ForumPost
        public IPagedList<ForumPost> ForumPostList { get; set; }

This way on my view I can have a list of ForumPost(s) and a form that would edit the post.

This is what i see in the debug mode right before the save call:

The problem is that when I try to Save/Update I get the following error:

I already tried doing this:



Introduction to strongly Typed Data Sets

This article teaches how to create a strongly-typed dataset class library in your C# database applications. Our objectives are as follows:

.Learn what an strongly-Typed Data Set is
.Let Visual Studio Create a ST Data Set
.(Semi)Manually create a ST Data Set using XSD (Xml Schema Definition)

partial view, 2 controllers



This is my first visit to the forums, I hope someone here can help me


I'm writing a small webapplication for creating repair tickets and adding comments, really basic

now I'm writing this in MVC2

So I have 2 controllers, 1 HomeController that does everything related to the tickets (listing tickets, creating new ones, editing) and 1 controller for the comments

the edit view for the homecontroller contains a partial view for /comment/create

so /home/edit/ticketnumber can edit the title and status of the ticket on the left side of the screen, the right side of the screen contains the partial view for adding comments

this is done like this:

Html.Renderaction("Create", "Comment");

but if I look at the generated html code when running the app, both save buttons go to /home/edit/ticketnumber

so the comment is never saved.


I hope this makes sense and that someone can help me solve this

Data Points: Efficient Coding With Strongly Typed DataSets


Someone once said to me that the hallmark of a good developer is the desire to spend time efficiently. Developers are continually pursuing ways to make coding easier and faster, and to reduce the number of errors.

John Papa

MSDN Magazine December 2004

Disappearing partial view


I have a view that uses a partital view.  The partial view is invisible when the page loads.  The user then clicks a button and I use Html.RenderPartial to make the view appear.

There is a button in the partial view in which the use will click which should make the partial view disappear.  How do I make the partial view disappear?

Thanks for the help!

How to create strongly typed datasets with access parameter queries



How can you create strongly typed datasets using an access database against access select statements that use parameters?

The problem is VS.Net doesn't allow select queries with parameters to be dragged onto a form, it only allows access queries without parameters!

I also tried the dataadapter wizard, but again it only allows me to select queries without parameters?

Many thanks in advance


Rendering Partial view postback with data posted back and entire view context

This is the base Index.aspx view:<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> <%@ Import Namespace="LMWebUI.Components" %> <%@ Import Namespace="LMWebUI.Models" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <% Session["HasScripts"] = "false"; %> <% if (Utility.FixNull(Session["LoggedIn"],"false") == "false" ) {%> <% ViewData["Login"] = new PartialRequest ( new { controller = "Account", action = "LogIn" } ); ((PartialRequest)ViewData["Login"]).Invoke(ViewContext); %> <%} else {%> <div>Logged In Content here</div> <%}%> <script type="text/javascript"> LMx.init(); </script> </asp:Content> This is a helper class> that I found elsewhere, doesn't solve the problem, but still works to display the viewpublic class PartialRequest { public RouteValueDictionary RouteValues { get; private set; } public PartialRequest(object routeValues

Strongly Typed DataSet Cleanup

Hey all, I've looked around and I can't seem to find a good answer on this. Is there any cleanup needed on a strongly typed dataSet? I'm using DataSets as my DAL but I don't really have a BLL. I'm handling this in my code behind like this: Private PunchAdapter As New PunchDSTableAdapters.PUNCHIMPORTTableAdapter Dim LastPunch As String = PunchAdapter.GetLastPunch(PersonNUM) PunchAdapter.InsertPunch(PunchID, ReqCode, PersonNUM, txtDate.Text, txtTime.Text) I'm assuming it handles the opening and closing of the connetion? The adapter has a dispose method. Should I be using this? Is there any cleanup necessary or does the partial class (that inherits system.data.dataset) handle all of this? Thanks!

Load View and Partial View (Master/Detail) with default parameter(s) ?

MVC newb.  Members view (index) that lists members that users can select to show a partial view in the same view with details for the selected member Uses jquery (Ajax.ActionLink) to call a partial view method in the members controller to then load the members detail section Works fine up to here....but I'd like to load the partial view with "member" details for a default or random member on initial load -- ie not through the Actionlink selection How do I invoke the partial view method on the initial load?  I'm sure this is basic stuff but still still getting my head around the mvc "way" Can someone point me to an example or explanation somewhere?  (not turning anything up on my searches thus far)   thanks in advance!!

Dynamic Javascript in Ajax Partial View

I have a partial view which uses Ajax.ActionLink to perform paging.  The AjaxOptions in the link identify the update target (a div on the main view) and some javascript to run OnSuccess (in the partial view).  The javascript must be in the partial view since there is some information in the partial view required to properly wire up the jQuery in the javascript.  This isn't working as expected.  The sample below is the minimum code to duplicate the behavior I am seeing: Controller: private static int count; // // GET: /Home/ public ActionResult Index() { ViewData["Test"] = count++; return View(); } [HttpPost] public ActionResult TestPartial() { ViewData["Test"] = count++; return PartialView(); } View:  <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Index</title> <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script> <script
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend