MVC :: Model With List As Member: Member Always Null After Submit?
Nov 25, 2010
I have following model class:
public class WebModel
{
public List<ArticleModel> Articles { get; set; }
}
public class ArticleModel
{
public int ID { get; set; }
public double ValueParam { get; set; }
}
Then I have the controller with the two actions:
[Authorize]
public ActionResult Index()
{
WebModel model = new WebModel();
ModelConverter.ConvertToModel(model, controller);
return View(model);
}
[Authorize]
[HttpPost]
[ValidateInput(false)]
public ActionResult Index(WebModel model, string saveButton)
{
ModelValidation.ValidateWebModel(model, ModelState);
if (ModelState.IsValid)
{
return RedirectToAction("Create", "Article");
}
ModelConverter.ConvertToModel(model, controller);
return View(model);
}
And this is my view:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Web.Models.WebModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<%var controller = Session["controller"] as Web.Code.SessionController; %>
<%Html.BeginForm(); %>
<div>
<table width="100%">
<%foreach (var article in Model.Articles)
{%>
<tr style="text-align: right">
<td>
<%:Html.DropDownListFor(m=>m.Articles.FirstOrDefault(f=>f.ID == article.ID).ID, new SelectList(controller.CurrentProdukt.Articles.AsEnumerable(), "ID", "Name", article.ID)) %>
</td>
<td>
<%:Html.TextBoxFor(m => m.Articles.FirstOrDefault(f => f.ID == article.ID).ValueParam)%>
</td>
</tr>
<%} %>
</table>
</div>
<table style="width: 100%">
<tr>
<td>
<input type="submit" name="saveButton" value="Save" />
</td>
</tr>
</table>
<%Html.EndForm(); %>
</asp:Content>
If I press the submit button, I get to the second action method in the controller (the one with the HttpPost attribute). In this action, the object model itself is not null, but the "Articles" list inside is null.
View 2 Replies
Similar Messages:
Feb 25, 2010
I have two member roles at my project:
1.) Administrator
2.) Member
From the toolbox in Visual Studio 2008, I have dragged and dropped the create user wizard into the stage. I aim that a guest can register itself and automatically join the "member" role. Not the role "administrator". How can I do that?
View 9 Replies
Dec 22, 2010
I am getting an exception on a linq to sql query:The null value cannot be assigned to a member with type System.DateTime which is a non-nullable value type.
[Code]...
View 3 Replies
Dec 26, 2010
I got the following error when i tried to insert a new record after the run my project, so what does this error indicates?
"{"Cannot insert explicit value for identity column in table 'Articles' when IDENTITY_INSERT is set to OFF."} System.Exception {System.Data.SqlClient.SqlException}
"
View 4 Replies
Dec 26, 2010
When i click on the page that represents a controller the following error was displayed:-
"The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type"
On this link of code
var articleapproval = articletyperepository.FindAllArticlesRequireMyApproval().ToList();
while the FindAllArticlesRequireMyApproval execute the following LINQ statement :-
var articleapproval= articletyperepository.FindAllArticlesRequireMyApproval().ToList();
where this methods calls the following LINQ statement:-
View 2 Replies
Nov 17, 2010
My code:
[Code]....
If the value is null writes out that error.How to check if the value is null? And if the value is null, I want to store + 1
View 1 Replies
Aug 29, 2010
I'm trying to create a member section for my website and a non member section. I want the nonmember pages to have access to all the member pages but just not certain features like saving to the database. Is there a way to have the same page for both members and non members but have certain controls like buttons and other things that are only usable to the member that is logged in?
View 5 Replies
Jan 26, 2011
I'm working on this big project in MVC ASP.NET w VB.NETOne of my views is getting me headaches since a few and i'm not sure what's up.I've used the Begin.Form and Html.Encode methods alot in my other views and i never had any problems. Now this new Create.aspx view for one of my object called Automation is giving me multiple build errors such as those cited in the title plus
Error 184 'Context' is not a member of
'ASP.views_automatisation_create_aspx'.
BeginForm is not a member of 'Html'
Encode is not a member of HTML
My header is as follow (just like all of my other working views headers) :
\
<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage(Of XXXXX_XXXXX.Automatisation)" %>
View 4 Replies
Dec 22, 2010
I am making a website to store invoices so i can mail them to clients. So i got a table for clients, invoices and one with invoice products/services. When an invoice has no products/services added to them and it returns null i get the error "the null value cannot be assigned to a member with type System.Decimal which is a non-nullable value type."
I just started with linq. Before i always used mysql. Mostly i just had to call data from 1 table so forgive me if my linq query isn't really correct.
Dim invoices = From i In db.invoices _
Group Join p In db.products On i.id Equals p.invoiceId Into invoiceProducts = Group _
Select New With {i.client.naam, i.titel, (From iP In invoiceProducts Select iP.prijs).Sum}
i show the client's name, the title of the invoice and the total amount the clients will need to pay for products and services.
View 1 Replies
Nov 5, 2010
I have my website without layers now i am converting code to layers.
When i add some page design and try to generate its designer file be cliking rite on that page and clik on option
"Covert to web application" it gives me error namespace cannot have space and sometimes it gives me error
System.exception was thrown error
My codefile name is correct and inherit name also correct like below
Source code is
<%@
Page
Language="VB"
AutoEventWireup="false"
StylesheetTheme="SkinFile"
CodeFile="Managewebsiteusers.aspx.vb"
Inherits="admin_Managewebsiteusers " %>
My page name is ManageWebSiteUsers and it is in admin folder
class file name is
Partial
Class admin_Managewebsiteusers
Inherits BasePage
View 3 Replies
Feb 17, 2011
I am getting this error whilie bulding project. i simply has defined a datatable accessing its rows and columns. don't knw why it says Columns is not a member of 'DataTable.
Error 66 'Columns' is not a member of 'DataTable'. E:DOI1TableReports.aspx.vb 342
Error 65 'Rows' is not a member of 'DataTable'. E:DOI1TableReports.aspx.vb 297
Error 73 'NewRow' is not a member of 'DataTable'. E:DOI1TableReports.aspx.vb 410
View 9 Replies
Jun 30, 2010
I am currently having a build issue with my project. I am using visual studio 2008 and C#
The problem is with my Redicrector and IRedirector files, and the error message is
[Code].....
I am following directions on the set up of my application and they make no mention of implementation.
View 3 Replies
Feb 15, 2011
I'm using MVC 2 application and it works well back then, but after I restart VWD2010 these errors comes up. [:(]
(1)
BC30456: 'RenderPartial' is not a member of 'Html'.
<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
<%Html.RenderPartial("/Views/Shared/EditEmployee.ascx")%>
'DropDownListFor' is not a member of 'Html'
<li>* Choose Country
<%= Html.DropDownListFor(Function(model) model.country, Nothing, New With {.class = "highlight"})%>
It's odd because all instance of 'Html' at Views are getting such errors. I did build/rebuild/clean the project but still the same errors.
View 1 Replies
Apr 26, 2010
I'm building a Javascript application and eash user has an individual UserSession. The application makes a bunch of Ajax calls. Each Ajax call needs access to a single UserSession object for the user.
Each Ajax call needs a UserSession object.
Data in the UserSession object is unique to each user.
Originally, during each Ajax call I would create a new UserSession object and it's data members were stored in the ASP.NET Session. However, I found that the UserSession object was being instantiated a lot. To minimize the construction of the UserSession object, I wrapped it in a Singleton pattern and sychronized access to it.
I believe that the synchronization is happening application wide, however I only need it to happen per user. I saw a post here that says the ASP.NET cache is synchronized, however the time between creating the object and inserting it into the cache another Thread could start construction it's another object and insert it into the cache.
Here is the way I'm currently synchronizing access to the object. Is there a better way than using "lock"... should be be locking on the HttpContext.Session object?
[code]...
View 2 Replies
Aug 20, 2010
when i try to run an web application in visual studio 2008.. i got this error...
'PopupWindow': member names cannot be the same as their enclosing type
also while correcting errors my startup web page changed..dont know how to setback the original startup webpage...
public partial class PopupWindow {
/// <summary>
/// frmPopupWindow control.
/// </summary>[code].....
View 1 Replies
Sep 9, 2010
i have the code to get the members of a local group example administrators
private void GetUserGrps()
{
using (DirectoryEntry groupEntry = new DirectoryEntry("WinNT://./Administrators,group"))
{
foreach (object member in (IEnumerable)groupEntry.Invoke("Members"))
{
using (DirectoryEntry memberEntry = new DirectoryEntry(member))
{
new GUIUtility().LogMessageToFile(memberEntry.Path);
}
}
}
Is there a way to get the groups a local user belongs to using directory services?
without using activedirectory or domain in it because i want for the local machine only and not for a domain.
View 1 Replies
Feb 24, 2011
I have an MVC 3.0 application which has been upgraded from MVC2.0. It currently has a combination or Razor and the old MVC 2 view engines running in it. I am getting quite frequently during development this error when browsing a razor-based page.
Compiler Error Message: CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember'
[No relevant source lines]
Source File: Line: 0
The error occurs frequently and seems to only affect a certain part of the site at a time. It also only affects pages using the ViewBag syntax so it is definitely the dynamic object stuff breaking. If i compile the project again it eventually goes away. The sporadic nature of the bug is very frustrating
View 2 Replies
Mar 10, 2011
I am getting this error when trying to run the page I have created.
In my vb file I have added the following to catch the select event:
[Code]....
As soon as I remove the line & me.gridPendingList.SelectedValue.ToString() the error goes away.. if I bypass the error and load the page anyway, the grid select button still produces what it is told to...
View 1 Replies
Jan 17, 2011
I Published my website from build and publish website after that am getting this error
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30456: 'CreateResourceBasedLiteralControl' is not a member of 'ASP.english_include_aright_ascx'.
Source Error:
[Code]....
Source File: D:inetpubvhostsmalathek.comhttpdocsenglishincludearight.ascx Line: 1
Show Detailed Compiler Output:
View 1 Replies
Jul 8, 2010
I have a profile variable, and when I load it then it is assigned default values. I need to check to see if it has ever been assigned. Typically I'd use an is null comparison but that won't work.
It was suggested I use the FindProfilesByUserName which seems backward. Regardless this method wont work as it only tells me if the user has any profile created but not for the specific member data I'm interested in. (It seems backwards because the whole purpose of the profiles was to make it easy to access the current user profile data. This seems like a bad design unless I'm missing something.)
The last option I can see is assigning bits to every object to see if they were dirtied or set. I don't want to do this unless required though.
Here is the FindProfilesByUserName sample :
ProfileInfoCollection profileInfo = ProfileManager.FindProfilesByUserName(ProfileAuthenticationOption.All, Membership.GetUser().UserName);
if (profileInfo.Count > 0)
{
if (profileInfo[Membership.GetUser().UserName] != null)
View 2 Replies
Nov 20, 2010
I can't seem to add a new member when using the CreateUserWizard.... All my validation seems to be working...I don't think it is wired up correctly though because: 1. No user is added to the database (remote) 2. CompleteWizardStep does not fireI tried to see if anything was happening by stepping through the page's VB code and flagged...AddUserWizard_CreatedUser sub...but it did not fire...I created a user using the built-in ASP.NET Configuration Wizard.. I also created a login file and I can successfully login.... just can't create a user with the CreateUserWizardmy hunch after some investigating is that I am missing something in my web.config file...I suspect I need something under the <authentication> tag???
View 3 Replies
Nov 25, 2010
I have a problem with Membership in ASP.NET. I'm using membership on my website. So far, I can create user and login using the created user account.
Then, I want to create an Administration Page which will display all users created in my membership DB (ASPNETDB).
I designed the layout and I want to display all the created users on a ListBox.
In the code behind, in Page_Load event procedure, I use this code:
[Code]....
When I compiled and tried this Admin Page, the Page gave me this error :
Server Error in '/MySite' Application.
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30456: 'GetAllUsers' is not a member of 'Membership'.Source
Error:
[Code]....
I think GetAllUsers() is a static member of Membership class, which we can use directly to get all the users in membership system.
View 2 Replies
Jan 31, 2011
I have a page called rateuser.aspx. Basically, this page allows one user (eg. me) to give a feedback on another user (eg: user b). These username should been retrieved when i logged in and when i go to user b's profile page. how do i retrieve these 2 different member id without clashing?Also, when i want to insert the feedback, how do i insert these 2 different id into the rateuser table w/o clashing because my member id is retrieved from the user table.
View 3 Replies
Feb 21, 2010
[Code]....
Is the best or only way to check if member has any roles at all, ak zero roles ?
View 1 Replies
Jan 15, 2010
i get the error
Error 1 'EnforceSSL' is not a member of 'MasterPage'. A:CommSiteRegister.aspx.vb 19 9
I addes the
<%@ MasterType
VirtualPath="MasterPage.master" %>
But still get the error
View 1 Replies