MVC :: Why Is ViewModel Coming Back With Some Null Properties
Jul 8, 2010
I have a simple ViewModel with 3 properties...I have some javascript going on where if a link is clicked, JQuery sets the values for 2 textfields (1 hidden) and a submit button where i process the rest of the Model on [HttpPost] - but for some reason some fields (the ones NOT set by javascript/JQuery) are coming back null - while on the page there is clearly values in them
[Code]....
And my Controller has the HttpGet and HttpPost, and a method that creates the nodes for the JQuery tree.
When you click on a node, this is when some values are set via javascript
[Code]....
View 4 Replies
Similar Messages:
Apr 22, 2010
I am using ASP.NET MVC 2.0 and I want to transfer my ViewModel properties to business object. I can do this manually or use AutoMapper or use new method available in ASP.NET MVC 2.0. My question is that does anyone know the name of the new method which allows to copy the properties from one object to another?
View 1 Replies
Mar 29, 2010
for SEO purposes, instead of refreshing the page every click of a product, is it possible to click on the product and when the server comes back with the response, to change the URL of the page to reflect the new link to information currently on page?
point is to have ajax redraw the product details portion of the page but have SEO friendly url's displayed so if people want to bookmark the currently selected product, it will bookmark the right url instead of the generic one to access the products page..
For example... here's my entry point:
Products.aspx
product1product2product3 If I were to click product1, the request goes to the server with roducts.aspx?id=product1 but the url is still products.aspx on the response meaning that when people bookmark the product1 item, and they send the link to a friend, the friend always gets the generic product.aspx page.
I'm trying to get around this without refreshing the full page (postback).
View 3 Replies
Jun 23, 2010
I have a website (not web application). I deleted all references in the code to some DLLs and deleted the dlls themselves, but
when I recompile they keep coming back. I tried with resharper and read 100 articles, but I can't get rid of those dlls! )-:
How can I get rid of the DLLs?
View 1 Replies
Feb 17, 2010
Let's say I have two pages on the same ASP.NET C# WebSite:
Page1.aspx does things in the Page_Load event
I navigate to Page2.aspx using the menu
Page2.aspx does some things then Response.Redirect back to Page1.aspx
Page1.aspx cannot do things in Page_Load event this time because it never fires.
I tried to turn off cache declaratively, tried using true for endResponse in my redirect... nothing seems to make a difference.
View 5 Replies
Mar 15, 2011
This is really weird - I've got a MVC app running, including a Login method in my ServicesController class:
public ActionResult Login() {
var p = Request.Params;
var userName = p["username"];
var password = p["password"];
// etc...
}
View 1 Replies
Jul 6, 2010
My web site is integrated into a client web site. Client web site reaches out to my site through an Xml request and I return Html embedded in an Xml response. Client site then displays the Html in an area on a page on their site. All is well so far...
Now, there is a link on the Html that does an HttpPost back to my site which causes a re-direct to another page on my site. i.e. [URL] -> HttpPost -> [URL]-> Response.Redirect("CookieTest.aspx"). Still, all is well. [URL]
All of the above can occur without authentication to mysite. Where I start running into problems is when CookieTest wants to do a FormsAuthentication.SetAuthCookie(). If I put a button on CookieTest that does FormsAuthentication.SetAuthCookie() and then Response.Redirect("SecurePage.aspx"), still under [URL], the SecurePage does not recognize the authentication because the auth cookie is not present.
1. Navigate straight to CookieTest.aspx
So I simplfied the problem into basic cookie set/read excercise and used the code below to test out cookie writing/reading ability. When I call the page directly from the browser I see that on initial load the response cookies are empty. Then on button click I see that the cookie is properly set in the response. Then on subsequent page refresh I see that the page load shows the request cookie.
2. Navigate to CookieTest.aspx in an HttpPost from [URL], as mentioned above.
Now on button click I see the cookie in the Response but do not see it come back in the Request of subsequent page refreshes, as if the client browser is rejecting cookies set by my server.
3. Navigate straight to CookieTest.aspx, then do the HttpPost from [URL]
In this case, since the cookie was set during a straight navigation to CookieTest.aspx, the cookie is present in the subsequent HttpPost/Redirect from [URL]. CookieTest.aspx has full access to the cookie and can even delete it.
4. Have CookieTest.aspx pop a new browser window simply sets the cookie and closes itself down.
Similar to #3, if the cookie is set through a popup window and then CookieTest is refreshed the cookie is present in the Request.
Notes:
The code does prove that the client browser accepts cookies.
When my page (CookieTest.aspx) is shown within the frame on the [URl] page, during any link back to my server, the Request.Url.Host shows my domain.
[code]....
View 3 Replies
Oct 25, 2010
I am using a CustomValidator in ASP.NET as follows:
<asp:CustomValidator ID="cvComment" ControlToValidate="txtComment" Display="None"
EnableClientScript="true" ClientValidationFunction="validateComment"
runat="server" ></asp:CustomValidator>
And this is the function that gets called:
function validateComment(source, args) {
var reComment = new RegExp("^[a-zA-Z0-9',!;?@#%*.s]{1,1000}$");
var validComment = reComment.test(window.event.srcElement.value);
if (!validComment)
alert("The comment has illegal characters");
args.IsValid = validComment;
}
Upon clicking the button that triggers the validator, the application breaks and I can see that the window.event property is null, so obviously there's a null reference trying to match the regEx. My question is why could the window.event be showing up as null? I could've sworn this was working before.
EDIT:
I have modified the function as such:
var check = document.getElementById(source.id);
var checky = check.attributes["controltovalidate"].value;
var checkyo = document.getElementById(checky);
var validHour = reOutHour.test(checkyo.value);
if (!validHour)
alert("The time is incorrectly formatted");
args.IsValid = validHour;
Now this is working on Internet Explorer, but not on Firefox...
View 1 Replies
Mar 23, 2011
I had a .net 4.0 vb.net page that was setting session variable and setting a hidden form value to the same value. It was a paypal buy now button. When the user selects it, they are sent to paypal for payment. If the transaction is good, they are redirected back to another page on my site and a hidden value is sent back with the invoice I originally sent them. They are sending the form value, but my session variable does not available.
From the user point of view it's all seamless.. Is it the same session? And should my session variable be available?
View 2 Replies
Feb 15, 2011
My Original Issue here:Help! I've got repository access in my MVC master page! Refactor time!What originated as a re factoring job to improve performance has revealed new issues. If I should keep this in my original question - feel free to delete this one, and rename the old one to something more relevant. I'm using an ActionFilter applied to a base controller to load some user-customized settings. My issue is that I save these settings in the filterContext.Controller.ViewData object but its coming through as null on my master page. Here is the relevant code:
Action Filter
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class StoreSettingsActionFilter : ActionFilterAttribute
[code]...
View 1 Replies
Mar 22, 2010
I am having a trouble while trying to create an entity with a custom view modeled create form. Below is my custom view model for Category Creation form.
[code]....
When i click on save button, it doesnt bind the category for me because of i am using custom view model and strongly typed html helpers like that
<%=Html.TextBoxFor(model => Model.Category.OrderNo) %>
My html source looks like this
[code]....
How can i fix this?
View 3 Replies
Jul 8, 2010
My problem is that when I submit the form and returning my viewModel of type QuestionViewModel - the Type is null.
See code below.
[code]....
View 1 Replies
Dec 24, 2010
I have a page in which I am not using cache by using this code:
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
Now I want to know: Is there any difference between coming to this page using a proper link or coming back using browser back button, or is there any way to detect this?
View 2 Replies
Feb 12, 2010
Tables: Article, Author, Comment (1 article and 1 author can have * comments)In the database is 1 article, 1 author and 1 comment.
The problem is, that code
myBD my_bd = new myBD();
var articles = by_bd.Article;
works OK, I can see that an Author and an Article has 1 comment. But that code
var comm = (from u in my_bd.Comment
where ......
select u);
returns the comment but it has NULL values in property Article and Author. Why ?
View 2 Replies
Mar 7, 2011
I am using ASP button its working properly at client side but on server side its not firing.
<div style="text-align: center">
<div>
<div id="UserName">
<b>LoginName</b>
<asp:TextBox ID="txt_LoginName" runat="server"></asp:TextBox>
</div>
</div>
<div>
<div id="Password">
<b>Password </b>
<asp:TextBox ID="txt_Password" TextMode="Password" runat="server"></asp:TextBox>
</div>
</div>
<div style="text-align: right; width: 210px;">
<asp:Button ID="btn_SignIn" OnClientClick="LogInUser()" UseSubmitBehavior="false" runat="server" Text="Login`enter code here`" />
<asp:Label ID="lbl_InValidError" runat="server"></asp:Label>
</div>
</div>
Client Side Code:
function LogInUser()
{
var LoginName = document.getElementById("<%=txt_LoginName.ClientId %>").value;
var Password = document.getElementById("<%=txt_Password.ClientId%>").value;
[Code]....
View 1 Replies
Nov 3, 2010
I have a new VS2010 .NET 4.0 Web project and the Properties Folder has gone wierd on me. It has lost teh "Open" under the right click. There is no way to get a Settings file created now.
I am unable to get to the Settings grid and no Settings file is created. I tried the help and it has the normal trip of select Properties, Open (right click), Settings Tab, etc. etc.
View 1 Replies
Apr 26, 2013
I have made a web page in which there is login screen when user login it goes next page but my problem is if i directly enter the url of that page it open. I want it should not open unless the user log in...
View 1 Replies
Mar 3, 2010
I am relatively new to ASP.NET. I am just wondering if there is way to read values from properties file (similar to rading a properties file from JSP or java).
For example if a property file has something similar to this:
[Code]....
I would like to read all the values for username_list (comma seperated) and also the value of is_valid.
View 2 Replies
Feb 16, 2010
its said that 1 ViewModel has 1 View. 1 View is for me a UserControl. What if my UserControl has different areas filled with data from different entities, do I have then several Views and need to build several ViewModels? e.g: I display in a UserControl 3 entities: customer(listbox),order(datagrid),product(datagrid). Each of those "data areas" has add+remove buttons and textboxes to enter data.
Actually each of those "data areas" are put in its own GRID having so the posibility to set a individual datacontext.
1.) Should I now create 3 ViewModels CustomerVM,OrderVM and ProductVM?
2.) Are those 3 "data areas" seen as an own sort of separated View, although I have not put them in 3 UserControls.xaml files ???
3.) When this one UserControl is inside a TabControl`s tabpage where do I load the 3 entities related data? Inside the MainViewModel? I want to show/load that data only when the user clicks the tabheader.
View 1 Replies
Jan 30, 2010
I have 2 properties in my ViewModel
class ViewModel1
{
Dictonary<int, string> PossibleValues {get;set;}//key/value
int SelectedKey {get;set}
}
I want to edit this using a Html.DropDownListFor I want to get MVC to auto serialize the data into/from the ViewModel so I can the following
public ActionResult Edit(ViewModel1 model) ...
View 3 Replies
Mar 3, 2011
I'm new to .Net development, and now are following NerdDinner tutorial. Just wondering if any of you would be able to tell me What is the differences between ViewData and ViewModel(all I know is they are used to pass some form of data from controller to view) and perhaps tell me on what situation should I use ViewData instead of ViewModel and vice versa
View 1 Replies
Mar 2, 2010
[HttpPost]
public ActionResult Edit(int id, FormCollection fc)
{
Movie movie =
(
from m in _ctx.Movie.Include("MovieActors")
where m.MovieID == id select m
).First();
MovieActorViewModel movieActor = new MovieActorViewModel(movie);
if (TryUpdateModel(movieActor))
{
_ctx.ApplyPropertyChanges(movieActor.Movie.EntityKey.EntitySetName,
movieActor.Movie);
_ctx.SaveChanges();
}
return View(movieActor);
}
However, I am not sure how to test this, and in general would much rather have the method take a typed model like:[HttpPost] public ActionResult Edit(MovieActorViewModel movieActor) Is this possible? What changes to my MovieActorViewModel class do I need to make in order to enable this? That class looks like this:
public class MovieActorViewModel
{
public Movie Movie { get; set; }
public Actor Actor { get; set; }
public PublisherDealViewModel(Movie movie)
{
this.Movie = movie;
this.Actor =
(
from a in this.Movie.Actors
where a.ActorID == 1 select a
).First();
}
}
The view is typed (inherits ViewPage) simple:
<% using (Html.BeginForm()) {%>
Movie Title: <%= Html.TextBoxFor(model=>model.Movie.Title) %><br/>
Actor Name: <%= Html.TextBoxFor(model=>model.Actor.Name) %>
<% } %>
View 3 Replies
Jun 20, 2010
I have used IDataErrorInfo Validation for my Model.
But when I use these model classes inside a view model, the validation does not happen.
sample viewmodel below
[code]....
Now, if Category or Subcategory classes are directly used as models for view, the validation works fine. But, if CategoryViewModel is used, no validation occurs.
View 1 Replies
Jan 9, 2011
I'm trying to get my own viewmodel after submit my form and I got the following error:
"Unable to cast object of type 'System.String[]' to type 'System.String'"
This is my code:
ViewMode:
public class SoftwarePackages
{
public string[] PermissionsList { get; set; }[code].....
View 3 Replies
Jan 19, 2010
A table can be used to automatically sense Model. But when I get more than one table after the SQL query is a DataTable. When this DataTable to return View (DataTable) later. In the aspx file, can automatically perceive it as the Model, as the self-paragraphs?
[Code]....
View 4 Replies