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

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

MVC2 UpdateModel method, with custom ViewModel and cruicially.... PartialViews.

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :ASP.Net
Hi, not usually one to ask for help but 2 days on this and not really getting anywhere. I have a view that gets posted back to my controller and I can call updatemodel pass in the FormCollection and everything in the view gets updated and works great etc... The problem is, this view contains several PartialViews that I just can't seem to get the UpdateModel helper to update. All this stuff is strongly typed, I mean my overall viewmodel has properties that expose the data to my partialviews. (just for clarity see below code, "Model" has a property called "AreaListViewModel", which has a property called Areas. "AreaList" is the partialview/usercontrol). <% Html.RenderPartial("AreaList", Model.AreaListViewModel.Areas); %> I'm convinced it is either something to do with the way I add the data to my partialview, like HtmlTextBoxFor syntax. OR the UpdateModel syntax. As mentioned I get my form data back as a "FormCollection". [AcceptVerbs(HttpVerbs.Post)]public ActionResult Details(int Id, FormCollection formData) Many thanks for any help/pointers.        

View Complete Post

More Related Resource Links

Custom mapping from formValues to ViewModel

Let's say i have simple ViewModel : class SimpleViewModel { public string prop1 {get;set;} public string prop2 {get;set;} } And I have following markup:<input type="text" id="prop1input" /><input type="text" id="prop2input" />I am wondering is it possible to make custom mapping from form values submitted via POST to model values, something like this:class SimpleViewModel { [HttpMappingAttr("prop1input")] public string prop1 {get;set;} [HttpMappingAttr("prop2input")] public string prop2 {get;set;} }

MVC2 NerdDinner - Data no longer saves after adding ViewModel

I am writing this post to document some issues I ran into, and hopefully help anybody else who gets stuck in the same place.  I am creating the NerdDinner application via the Professional ASP.NET MVC 2 book,  and once I got to the ViewModel part (pages 88-91), I noticed none of my data was saving any longer.  I discovered several errors and areas of confusion in these pages of the book, which I will list now. Page 88:  When it says to add the DinnerFormViewModel class, it doesn't say what folder to add it to.  On page 89, the Inherits example (NerdDinner.Controllers.DinnerFormViewModel) implies it was added to the Controllers folder, but if that were so, the code on page 88 would need to use Models.Dinner instead of just Dinner.  No big deal; just put it in Models and change the Inherit statement on page 89 to use NerdDinner.Models.DinnerFormViewModel. Page 89:  At the bottom of the page is some wrong code.  Since the properties of Dinner are now one level deeper, all references to m.Title, m.Country, etc, need to be m.Dinner.Title, m.Dinner.Country, etc.  The statements above the code are also incorrect ("Notice... we are not changing the names of the input elements... the form elements will still be named...") -- the form elements will actually change from "Title", "Country&quo

(MVVM): Call Method On ViewModel From View

Hey All,   In my View, I would like to call a method on my ViewModel (all from XAML). View: <!--Parameters--> <ListView Grid.Row="2" DataContext="{Binding}" ItemsSource="{Binding}"> <ListView.View> <GridView AllowsColumnReorder="True"> <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Key}"/> <GridViewColumn Header="Value"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBox Text="{Binding Value, Mode=OneWay}" MinWidth="100" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> ViewModel (the Method I want to call): public ReadOnlyScriptParameterCollection GetParameters(string scriptFullTypeName) { ReadOnlyScriptParameterCollection sps = null; var scriptHost = ScriptHost.Create<JdsScriptHost>(); scriptHost.LoadFromAssembly(ScriptAssemblyPath, scriptFullTypeName); sps = scriptHost.ScriptParameters; return sps; } Is there

BCS Method Security / External Content Type Permissions / Custom List Security Provider / Security T


I have an external list setup with the usual CRUD methods.  The external SQL table is also being populated by another source.  I want to enable/disable deleting depending on whether the record was created from SharePoint.  I would also like the normal list permissions to work.  So if a user has permissions to delete on the list, they can only delete items created for SharePoint. 

Where should this logic be incorporated?  On the BCS Delete method, somewhere in the External Content Type or on the list instance?  Most examples I find relate to security trimming for search.  I'm only concerned about the delete method.

I'm sure there are multiple ways to accomplish this.  Which is the best?


ASP.NET MVC2 Custom routing with wildcard or free text url


I have a requirement to add specific functionality to an asp.net mvc2 web site to provide addtional SEO capability, as follows:

The incoming URL is plain text, perhaps a containing a sentence as follows

"http://somesite.com/welcome-to-our-web-site" or "http://somesite.com/cool things/check-out-this-awesome-video"

In the MVC pipeline, I would like to take this URL, strip off the website name, look up the remaining portion in a database table and call an appropriate controller/view based on the content of the data in the table. All controllers will simply take a single parameter bieng the unique id from the lookup table. A different controller may be used depnding on different urls, but this must be derieved from the database.

If the url cannot be resolved a 404 error needs to be provided, if the url is found but obsolete then a 302 redirect needs to be provided.

Where the url is resolved it must be retained in the browser address bar.

I have had a look at the routing model, and custom routing and can't quite work out how to do it using these, as the controller would not be predefined, based on a simple route. I am also unsure of what to do to provide 404, 302 back to the headers also. Perhpas I need a custom httpmodule or similar but going there went beyond my understanding.

This must be possible someho

InternalStartup method erro when publish InfoPath form with custom code


Hi All,

I created a SharePoint Form Library, and added a button in the form. Then, by following the steps of adding custom code. I was trying to add codes to the button click event in VSTA. When I try to publish this form to my SharePoint library, I got an error message say:

"The form template has been published to the server but it can only be opened in InfoPath Filler.

There is an error in the InternalStartup method of form code.

There may be additional error detials in the Design Checker task pane."

However, I did not make any changes to the InternalStartup. and then I tried to create another SharePoint Form Library Form in InfoPath Designer, and just add click event, but did not input any code, I got the same error. So I believe this is caused by either environment or the configuration of SharePoint Server. Could anyone help me out? Thanks!

Best method for creating a site definition containing a custom list instance



I want to create a new site definition which, when provisioned, includes an instance of a custom list. The custom list definition is contained in a feature as part of the site definition project. What's the best method for creating an instance of this custom list?

I can think of a few ways to do it:

- Modify the onet.xml for my site definition to include an instance of the list

- Use feature stapling to enable my custom list defintion feature when a site is provisioned using my new site definition and include a list instance in the feature.

Is there another more suitable method?



Need help setting up a Custom Security Trimmer, CheckAccess method not working.


I'm implementing the custom security trimmer for SharePoint server as outlined here: http://msdn.microsoft.com/en-us/library/ee819923.aspx

I have been able to successfully deploy the solution on to the server, but know I need to write the script that will check whether users have access to particular documents or not. The code in the walk-through is the following:

public BitArray CheckAccess(IList<String> documentCrawlUrls, IDictionary<String, Object> sessionProperties, IIdentity passedUserIdentity)
            BitArray retArray = new BitArray(documentCrawlUrls.Count);
            //Use passedUserIdentity to get the identity of the user who issued the query.
            IClaimsIdentity claimsIdentity = (IClaimsIdentity)passedUserIdentity;
           //IClaimsIdentity is defined in Microsoft.IdentityModel.Claims;
            for (int x = 0; x < documentCrawlUrls.Count; x++)

Webservice versions.asmx: Getversions-method returns error on an item of a custom list.


I using GetVersions from the webservice http://server/_vti_bin/versions.asmx. This method works Okay in SharePoint 2007, and in SharePoint 2010 it also works Okay on documents from a document library. But when I used on an item from a custom list, it returns an error stating: "Value cannot be null.\r\nParameter name: key". In SharePoint 2007 I could retrieve the histroy on an item with the call GetVersions("Lists/MyCustomList/5_.000"), in SharePoint 2010 this fails.

Do I need to change the parameter, or use another filename for an item instead of "5_.000"? Does any one have the same experience?

Thank you

How to hide a method while creating custom control by inheriting WebControl?



I am creating a custom control by inheriting a server control, say LinkButton. There are properties like "BorderColor" available in LinkButton. Let's say, I don't want this particular property to be available when I create an instance of the custom control.

I want to completely hide this particular property (I don't want to override it but disable it.)

My code is as follows:

    Class MyLinkButton
        Inherits LinkButton

        'I want to hide the following method in such a way that if an object of MyLinkButton is created, the following property is not available
        Public Overrides Property BorderColor As System.Drawing.Color
                Return MyBase.BorderColor
            End Get
            Set(ByVal value As System.Drawing.Color)
                MyBase.BorderColor = value
            End Set
        End Property

    End Class

Can anyone help me with this oir provide few pointers?

Best method for typing a custom object thru a web service


I have several web services with a custom business object being used as a parameter (MyNamespace.MyBizObj).

After I create my web references that same  business object gets retyped to whatever web service that is is in Example:

webserviceRef1.MyBizObj, webserviceRef2.MyBizObj, webserviceRef3.MyBizObj


Right now my UI isn't allowing me to retype this object back to the object that I need. In essence I need one unified version of this object that I can use across web services.

My custom class, Why method table only contain 4 methods?

using System;
using System.Text;

namespace C2
{ class TypeSample { TypeSample(int x, int y, int z) { coordinates.x = x; coordinates.y = y; coordinates.z = z; } private struct Coordinates { public int x; public int y; public int z; } private Coordinates coordinates; public void AddCoordinates() { int hashCode = GetHashCode(); lock (this) { Coordinates tempCoord; tempCoord.x = coordinates.x + 100; tempCoord.y = coordinates.y + 50; tempCoord.z = coordinates.z + 100; System.Console.WriteLine("x={0}, y={1}, z={2}", tempCoord.x, tempCoord.y, tempCoord.z); } } static void Main(string[] args) { TypeSample sample = new TypeSample(10,5,10); sample.AddCoordinates(); } } }

I always get 4 methods information in method table.
0:000> dd 009d308c
009d308c  00000000 00000014 00040011 00000004
NO main,  AddCoordinates and ctor
Have no idea of it,  Any help will be appreciated greatly. Thank your help very much!

See details below:

1. Use windbg to open this PE
2. .load sosex.dll
3. !bpsc TypeSample.cs 41
4. !bpsc TypeSample.cs 34
5. g

0:000> !loadby sos.dll mscorwks

Dialogs and ViewModel - Using Tasks as a Pattern

The ViewModel/MVVM pattern continues to gain popularity, with a blog post showing up every so often, and with tweets and retweets popping up even more often :-). At the same time, there are some interesting topics beyond the core pattern that continue to fuel experimentation. A big one amongst those is how should applications use dialogs when using the view model pattern.

The crux of the problem is the desire to keep the view model independent of UI concerns, and ensure it can be tested in a standalone manner, but that often comes to odds when you want the view model to launch a dialog, and/or do some work after the dialog is closed.

Custom Controls in C# .NET

Embedding user controls in a Windows form is just like adding a simple button or text box that are already provided with .NET. These basic controls were written essentially like you code your own controls. Typically the controls you design are to be used in multiple forms or to modularize your code. These reasons help reduce the amount of code you have to type as well as make it easier for you to change your implementation. There should almost never be any reason to duplicate code because it leaves a lot of room for bugs. So, implementing functionality specific to your control in the control's source code is a good idea. This reduces code duplication as well as modularize your code, which is a good programming guideline.

Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

A Generic Dialog ViewModel

I worked on a wpf viewmodel for dialogs, because it seemed strange to me that you needed for instance windows forms dialogs to open or save files in wpf. So I set about creating my own wpf dialogs. After creating the dialog viewmodels there still remained a small issue with the library and also I didn't have much time to write an article about it. I however published the library containing the viewmodels for dialogs with another article on my blog

Writing custom MembershipProvider

ASP.NET Membership mechanism allows to use the build-in server tables to store and retrieve user data. By default, this mechanism can only be used with SQL Server database to which Microsoft provides suitable MembershipProvider class.
Inheriting from this abstract class, developer can use his own table(-es) from any database and use any database engine other than SQL Server, like Oracle, DB2 etc.
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