MVC :: Run Code Error Throw / Model Is Null ?

Mar 6, 2011

When i run code error throw ,my model is null. When i try to debug controller method my debuger dont goto controller code, Why that?

View 3 Replies


Similar Messages:

ADO.NET :: Make Linq Throw Error When Not Null Fields Are In The Table?

Jan 19, 2011

How to make the linq throw error, when not null columns are there in the table.

Why I am saying, it is. I tried to add to column in the table. Linq throwed error os some sort. I could not understand. it was like some innner table etc.

I had to resort to native sql, which showed the error, as the not null fields are there in the table.

View 5 Replies

Web Forms :: Send Mail Error / When Throw Code To The Server,programm Throws An Exeption?

Apr 16, 2010

Following problem occurred:
sending mail error

code for sending mail:

private void SendMail (string from, string to, string subj, string body, string dom)
{
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage ();
mm.From = new System.Net.Mail.MailAddress (from);
mm.To.Add (new System.Net.Mail.MailAddress (to));
mm.Subject = subj;
mm.IsBodyHtml = true;
mm.Body = body;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient (dom);
client.Send (mm);
}

error (exeption):

The server has violated protocol Server Response: <some code> // was translated from russian

if I test on my computer, everything works perfectly When I throw code to the server,programm throws an exeption

View 5 Replies

Forms Data Controls :: Throw The Exception Back To Page_Load Error: ArgumentNullException Was Unhandled By User Code

Nov 19, 2010

I'm trying to throw the exception back to Page_Load but the throw statement causes error: ArgumentNullException was unhandled by user code. How can that be fixed? Also, I can't see Label1.Text displayed on the page after the ArgumentNullException occurs because the page is not re-load. If there is no exception, it's fine to not reload the page. How can I see the Label1.Text displayed?

protected void Page_Load(object sender, EventArgs e)
{
try
{
...do something here...
}
catch (ArgumentNullException ae)
{
System.Diagnostics.Debug.Write(ae.Message);
Label1.Text = ae.Message;
Label1.Style.Add("visibility", "visible");
}
catch (Exception ex)
{
...do something here...
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)............................

View 3 Replies

Trying To Use AutoMapper For Model With Child Collections, Getting Null Error In .Net MVC 3

Feb 26, 2011

I'm completely new to AutoMapper, and I have a View that looks like this:

@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Consultant</legend> [code]...

This is pretty much the same error I got when trying to use the entity object directly as model, rather than having AutoMapper create a ViewModel. So what am I doing wrong? This is driving me crazy...

UPDATE 3:Well, neverending story... I found some info on using UseDestinationValue on the CreateMap method in AutoMapper. So I tried that, and well, that actually got me a bit further. But...now I get a new exception on SaveChanges() (in the EF model). The exception now is: "The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable." This appears to be an exception that also occurs when trying to delete child objects in a one-to-many relationship if you don't have cascade delete set, but that's not what I'm trying to do here...

Here's the updated CreateMap methods:Mapper.CreateMap<ConsultantViewModel, Consultant>().ForMember("Id", opts => opts.Ignore()).ForMember(
x => x.Programs, opts => opts.UseDestinationValue());
Mapper.CreateMap<Consultant, ConsultantViewModel>();

View 1 Replies

C# - Calling Membership Validateuser Method From Another Project In Same Solution Throw Null?

Oct 25, 2010

I have a webservice project and a web project in the same solution.

The web project implements a membershipprovider.

I want to be able to authenticate user via the webservice project but when i call this method in the webproject:
public static bool AuthUser(string userName, string password)
{
return Membership.ValidateUser(userName, password);
}

I get this inner ex."Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed." Calling the method from the webproject works fine. I understand why I get the ex. but not how to solve it.. UPDATE Well I fixed the issue by deleting the C:UsersJRBAppDataLocalMicrosoftMicrosoft SQL Server DataSQLEXPRESS folder.. However now the method always returns false.. It almost seems like it doesn't use the proper connectionstring.

View 2 Replies

IIS Throw Away URL Fragment On Custom Error Pages?

Nov 5, 2010

I'm using the old 404-rewrite method on a certain site that is tied to IIS6 *. So if I enter [URL] it calls my error page like so [URL]
Except if I call the page with a fragment, like [URL] I get the same result as above. I can't find the fragment anywhere:

Request.Url
Request.Url.OriginalString
Request.UrlReferrer
Request.RawUrl
headers, server variables, etc

This has come up because I want to resolve paths created by AJAX to their server-side versions. Is there any way for me to retrieve the original path from my handler?

View 1 Replies

DataSource Controls :: Error Msg "Null Reference Was Unhandled By User Code"

Jan 16, 2010

I downloaded a sample Rolodex from here: [URL] the file to download is at the bottom of the page and it is called 'RolodexDatalist.zip (6.71 kb)' So I changed the HTML to it points to my SQL Server DB. I changed the ConnectionString to this:

<connectionStrings>
<add name="CustomersConnectionString" connectionString="Data Source=EXCEL-4J2W8KYNPSQLEXPRESS;Initial Catalog=Customers;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

Now, everything points to my DB! I thought, ok great, this should be pretty easy. However, when I debug, I get this error message: 'Null reference was unhandled by user code. Object reference not set to instance of an object. Troubleshooting Tips: use the "new" keyword to set an instance of an object.' This line is yellow:

Dim conStr As String = ConfigurationManager _
.ConnectionStrings("conStr").ConnectionString
Here is the code-behind:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
ViewState("CurrentAlphabet") = "ALL"
Me.GenerateAlphabets()
Me.BindDataList()
End If
End Sub
Private Sub BindDataList()
Dim conStr As String = ConfigurationManager _
.ConnectionStrings("conStr").ConnectionString
Dim con As New SqlConnection(conStr)
Dim cmd As New SqlCommand("spx_GetContacts")
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@Alphabet", ViewState("CurrentAlphabet"))
con.Open()
dlContacts.DataSource = cmd.ExecuteReader()
dlContacts.DataBind()
con.Close()
If ViewState("CurrentAlphabet").ToString().Equals("ALL") Then
lblView.Text = "all Contacts."
Else
lblView.Text = "Contacts whose name starts with " & _
ViewState("CurrentAlphabet").ToString()
End If
End Sub
Private Sub GenerateAlphabets()
Dim alphabets As New List(Of Alphabet)()
Dim alphabet As New Alphabet()
alphabet.Value = "ALL"
alphabet.isNotSelected = Not alphabet.Value _
.Equals(ViewState("CurrentAlphabet"))
alphabets.Add(alphabet)
For i As Integer = 65 To 90
alphabet = New Alphabet()
alphabet.Value = [Char].ConvertFromUtf32(i)
alphabet.isNotSelected = Not alphabet.Value _
.Equals(ViewState("CurrentAlphabet"))
alphabets.Add(alphabet)
Next
rptAlphabets.DataSource = alphabets
rptAlphabets.DataBind()
End Sub
Protected Sub Alphabet_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim lnkAlphabet As LinkButton = DirectCast(sender, LinkButton)
ViewState("CurrentAlphabet") = lnkAlphabet.Text
Me.GenerateAlphabets()
Me.BindDataList()
End Sub
End Class

View 8 Replies

Unable To Throw Custom Error Handler From Within An Exception / "UnableToOpenDatabaseException Was Unhandled"

Jul 25, 2010

Why can't I throw a custom exception from within an Exception? In code below, I get error msg "UnableToOpenDatabaseException was unhandled" even though I have catch statement for it. What am I doing wrong? and how to fix it?

[Code]....

View 3 Replies

Embedded Javascript In Master Page Throw "Object Expected Error"

Jun 8, 2010

I'm semi-new to writing ASP.Net applications using master pages and I've run into an issue I've spent some time on but can't seem to solve.

My situation is that I have a master page with a structure that looks like this:

<head runat="server">
<title>Test Site</title>
[code]...

When I run this page and click on the image I get an "Object Expected" error.However, if I place the test function into my Default.js external file it will function perfectly.

View 1 Replies

MVC :: View Model Property Become Null?

Nov 8, 2010

So I have code as below

public ActionResult Create(AccountClassificationCreateViewModel ACCVM)
{
if (ACCVM.newMtn0130 == null)//Why ACCVM.newMtn0130 is null after [code]...

I wonder why the ACCVM.newMtn0130 become null after RedirectToAction? I already assign with "_ACCVM.newMtn0130 = newMtn0130".

ACCVM._Error didn't become null after RedirectToAction.

View 5 Replies

MVC :: Instead Of Null, The Model Inserts A 0 Into The Database?

Aug 3, 2010

I have a group of radiobuttons. The field they are 'bound' to is of datatype tinyint (sql server), byte .NET. It is set to NOT accept nulls in the database column (col1) and no default value has been set for the column, or indeed, anywhere else.

View code as follows:

<ul> <li><%= Html.RadioButton("col1", "1")%></li> <li><%= Html.RadioButton("col1", "2")%></li> <li><%= Html.RadioButton("col1", "3")%></li></ul><%= Html.ValidationMessage("col1", "*") %>

If the user doesn't select any of them, I would expect null to be that the model would attempt to insert into the database. I would therefore get a validation error that I can display to the user, prompting them to choose one of the options.

However, instead of null, the model inserts a 0 into the database. As this does not fail, no error is raised.

I am not setting the default value to 0 anywhere, not in the mvc app or the database

View 8 Replies

C# - Migrating From Website Project To Web Application Project In Visual Studio 2010 Causing All Controls To Throw Error?

Mar 29, 2011

I recently updated my VS2010 website project from .NET 3.5 to 4.0. Everything was working fine in the website project. Today I decided to migrate the website to a web application project as I have learned this is the best way to work in .NET. I split out all my class files into a separate class library and copied all my other content into my new project. Then I updated all the references and web.config.

When I build the class library, everything works great. The problem is happening when I try to build/debug the web application project. It is acting like all the controls are missing and it is also throwing a bunch of compile errors about the public properties I have in my master pages.

Control errors: "The name 'INSERT CONTROL NAME HERE' does not exist in the current context"

Master page errors:'System.Web.UI.MasterPage' does not contain a definition....

It is giving these errors for every single control and master page property in my entire solution.I notice when I add a new web.form to this project, it also adds a filename.aspx.designer.cs file in addition to the .aspx and .aspx.cs file. My existing files do not have these extra files since they were created in a different .NET version.

UPDATE: It seems I was missing the step where I need to right click on the new application folder and select "Convert to web application". I just did that and it seems to be a little bit better...

Now it is choking on Literals that are inside single quotes:

<div class='<asp:Literal ID="CssClassLiteral" runat="server"></asp:Literal>'>

It doesn't see this literal when it does the conversion... Is the above valid code or should I implement that functionality another way?

View 1 Replies

MVC :: ViewData.Model Null Reference Exception

Jan 19, 2010

My controller calls a class in my model which is getting data from a REST web service. The class in the model then passes the data back to the controller using an IList, like so:

[Code]....


My problem is this: The data that is held in the IList isn't there until the user has done a search in the View, submiting a form. This is a basic search function with 2 textboxes and a submit button in a form. When the user clicks submit, the controller action is called, the web service is then called, and the data in the IList gets populated. The problem is that in the View I am using a strongly typed view and my model reference in the foreach loop throws a Null Reference Exception because there is no data in it, because a search has not been conducted yet...
[Code]....

So, how can I have the above foreach loop in my view if there isn't any data in the model until a search has been conducted? Is there a better way that I should be doing this?

Essentially, what's the best method for passing data back to a view that is based on a form submittion?

View 6 Replies

MVC :: Model Binding To Non-null Arrays Fail. Is This A Bug?

Mar 12, 2010

I have several models that implement a array property using null object pattern in the following manner:

[Code]....

The problem is that any time I attempt to bind to a property of this type the DefaultModelBinder.CollectionHelpers.ReplaceCollectionImpl method wants to call ICollection<T>.Clear() and then ICollection<T>.Add() on the zero length array.

The real issue seems to be in DefaultModelBinder.BindComplexModel() method however. The method contains an explicit check for arrays and special handling to account for the fact that they don't support clear/add functionality. The problem is that the check stipulates that the array model must also be null. If it is non-null, normal ICollection<T> handling ensues which presumes support for clear and add. Can any one explain why the null check is there? It seems to me that either 1) the null check should be removed to permit replacement based binding to non-null arrays or 2) an explicit error stating that non-null arrays are not supported should be thrown.

I vote for the former. I can understand that in general, replacing an existing model with a refrence to a different model would be considered a bad thing. The calling code would not expect this in general and it could lead to hard to find bugs. However, in the case of arrays, if the calling code expects the array property to be modified at all, then I think the normal expectation would be that such modification would occur via replacement of the array.

View 1 Replies

MVC Null Model Passed To Controller Action?

Mar 31, 2011

Why is a null parameter being passed to the following controller action?

public FileContentResult GetImageForArticle(ArticleSummary article)
{
if (article == null || !article.ContainsValidThumbNail()) return null;
return File(article.ThumbNail, article.ThumbNaiType);
}

from the following partial view:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<AkwiMemorial.Models.ArticleSummary>>" %>
<%if (Model.Count() > 0) [code]...

View 1 Replies

MVC :: JQuery Disabled TextBoxFor Causes Model Fields To Be Null?

Jul 19, 2010

So i'm working on the form that i started MVC with - the problem is that i'm NOT using a ViewModel for the view, its an actual Linq to SQL object. And so far it works fine. This form is a beast and id rather not refactor it to use viewmodels....

My big problem now is that depending some condition, i pretty much set almost everything to disabled when a particular dropdown is selcted (to mimic a deactivated state) - when the user hits submit, the model fields are now null, even tho you can see them filled in (just greyed out and unselectable) and validation refuses them.

Is there anyway around this other than to refactor the Views to use ViewModels (and set different validation rules so submit works)?

View 4 Replies

Mvc File Upload Is Passed As Null To View Model?

Aug 19, 2010

I have a form which uploads a photo to my database, and I use a view model to aid in this process.

View Model:

public class GalleryViewModel
{
//Members:
public Gallery _photo { get; set; }
public string _title { get; set; }[code]...

When I debug the code, I see that the in the post method in my controller, all the information from the form is updated in the view model except for the uploadFile which is null.In the form I use enctype = "multipart/form-data". When I use my master page the uploadFile is null but when I use the default MVC master page everything works fine.

Here is my master page:

<%@ Master Language="C#" MasterPageFile="~/views/Shared/GeneralMaster.master" Inherits="System.Web.Mvc.ViewMasterPage" %> [code]....

View 2 Replies

MVC :: Model Validation Happens Automatically With LinqToSql DateTime Fields, But Not Other NOT NULL Fie...

Mar 15, 2010

I'm using MVC 2 with some Models from a LinqToSql project that I built. I see that when I post back to a Controller Action after editing a form that has a DateTime field from the Model, the MVC Html.ValidationMessageFor() helper will nicely display an error beside the Date text box. This seems to happen automatically when the you test ModelState.IsValid() in the Controller Action, as if the MVC model binding automatically knows that the DateTime field cannot be empty.

My question is... I have some other string fields in these LinqToSql generated classes that are Not-Nullable (marked as Not Nullable in Sql Server which passes thourgh to the LinqToSql generated classes), so why doesn't Mr. MVC pick up on those as well and display a "Required" message in the ValidationMessageFor() placeholders I have added for those fields?

Sure, I have successfully added the MetadataType(typeof<t>) buddy classes to cover these Non-nullable string fields, but it sure does seem redundant to add all this metadata in buddy classes when the LinqToSql generated classes already contain enough info that MVC could sniff out. It MVC validation works with DateTime automatically, why not these Not-nullable fields too?

View 4 Replies

Unable To Display/write Specific Html If Model / Entity Is Null

Jun 28, 2010

Normally I work in ASP Classic, and am still a bit green on ASP.Net MVC.

I have my model with its fields or entities (might not be the right word hence why not able to find if previously answered, forgive me), and some of these will have null values such as hyperlinks, email address, specific types of phone numbers, etc.

What I want to do is not write certain blocks of HTML within the foreach loop if a field is empty.

In ASP Classic, I would have written an If statement along the lines of:

<% If RS.field <> NULL then %>HTML with <%=RS.field %><% End If %>
<% If RS.field2 <> NULL then %>HTML with <%=RS.field2 %><% End If %>
...

However, I don't know how to achieve the same result in ASP.Net MVC.In one of my current usages, a list of sellers returned for a specific set of search results, it runs through a foreach loop and returns the current HTML (in part):

Website: <a class="url" href="<%= seller.ContactWebsite %>" target="_blank" title="Visit the website for <%= seller.Name %>"><%= seller.ContactWebsite %></a><br />

So, if for example I have a field from the model, say seller.ContactWebsite, and this field was NULL, I would not want it to write this as part of the foreach loop.

View 1 Replies

Web Forms :: Microsoft JScript Runtime Error On Page - "null" Is Null Or Not An Object

May 17, 2010

m getting this error again and again. i m also using the ajax modalpopup extender in my page ..

View 3 Replies

Web Forms :: Microsoft JScript Runtime Error - "null" Is Null Or Not An Object

May 13, 2010

My site was woking fine, now i noticed that i get an error "Microsoft JScript runtime error: 'null' is null or not an object" when i checked the view source, i saw the following system generated code

<script type="text/javascript">
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
&nbsp;&nbsp;&nbsp; ValidatorOnLoad();
function ValidatorOnSubmit() {
&nbsp;&nbsp;&nbsp; if (Page_ValidationActive) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ValidatorCommonOnSubmit();
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; else {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true;
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WebForm_AutoFocus('txtMailAddress');// --> IS THIS RIGHT???? out side the braces???
</script>
</form>
</body>
</HTML>

and a reference to this line below

<IFRAME id="__hifSmartNav" name="__hifSmartNav" style="display:none" src="/m2qa/WebResource.axd?d=fvL5WUdiCo1B4KvdiJfkfg2&t=633546432952161750"></IFRAME>

View 3 Replies

AJAX :: Error: Microsoft JScript Runtime Error: Sys.ArgumentException: Value Must Not Be Null For Control

Mar 31, 2011

I have an asp:BulletedList controls with AJAX:PagingBulletedListExtender on my aspx page.

It gives error as: Microsoft JScript runtime error: Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element

If I removed, the asp:BulletedList controls and AJAX:PagingBulletedListExtender from my page then page run without any error.

I am not getting the cause of the error.

View 3 Replies

MVC :: Nullable DateTime And DatePicker - Dictionary Requires A Non-null Model Item Of Type 'System.DateTime

Apr 1, 2011

I have a problem:

I've created usual Controller and View(Edit view) for editing my Entity (EntityFramework)

Here is view example:

<div class="editor-field">

@Html.EditorFor(model => model.BirthDate)

@Html.ValidationMessageFor(model => model.BirthDate)

</div>

BirthDate is Nullable<DateTime>

but during loading my View I get this exception

The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.

That's because of BirthDate is null in database but it is nullable and I expect that it just leaves the filed empty.

And I have Shared EditorTemplate:

@model System.Nullable<System.DateTime>

@if (Model.HasValue)

View 2 Replies

MVC :: Bug - Model Does Not Get Updated When Changed In Code ?

Feb 3, 2010

I have a page that shows the value of a property of my model. The value of that property is changed in the action-method of the controller (that recieves the model as a parameter). It turns out that this line of code:

<%= Html.TextBoxFor(m => m.Problem)%>

does not represent the value that it got in the action-method-code (just the value it got from the POST), but this does:

<input type="text" value="<%= string.IsNullOrEmpty(Model.Problem) ? "" : Html.Encode(Model.Problem) %>" />

Is this a bug or is some caching-mechanism working against me?

BTW, it is especially annoying when using HIDDENs, because the user can never change that value at all... That's how I found out...

I have a demo-project demonstrating the problem here for download. It is based on the default-application, so very small.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved