I realized that it is difficult to serialize an XML formatted string hence instead of XML formatted string I decided to post List of Key value pair instead. This approach is working fine.
AumSingh
Posts
-
Not able to Ajax post knockout (KO) data in XML format -
Not able to Ajax post knockout (KO) data in XML formatI am working on .NET 4.0 MVC project. I am trying to Ajax post a piece of data from my KO model. That data is a string in following XML format.
I am trying to post it like this.
$.ajax({
url: destUrl,
data: ko.toJSON(DataToPost()),
type: "POST",
success: function (result) {
// I am doing my stuff here.
}
},
error: function (request, textStatus, errorThrown) {
alert(request.statusText);
}
});Here you will notice the data being sent is "ko.toJSON(DataToPost())". DataToPost() returns the XML string contained in my KO model data member DataToPost. ko.toJSON() is used to convert the KO model data in JSON. This throws a runtime exception which is normally thrown when we post anything containing javascript or html tags. This is a security feature by .NET. Following is the exception.
A potentially dangerous Request.Form value was detected from the client.
<SearchCriteria><Criteria SearchOn="...est 3\" /></SearchCriteria>
I faced similar situation sometimes back (though I was not using KO that time and it was normal post i.e. non Ajax). I overcame the problem that time by using javascript escape() but this time it failed. I used it as follows
$.ajax({
url: destUrl,
data: ko.toJSON(escape(SearchCriteria())),
type: "POST",
success: function (result) {
// I am doing my stuff here.
}
},
error: function (request, textStatus, errorThrown) {
alert(request.statusText);
}
});Other popular fix is to disable this security either at page level or at application level. It could be done as follows. Page level.
<%@ Page validateRequest="false" %>
Application level.
But doing away with this security is not good. I don't think it will be a wise move. Right now I don't know what to do. Need suggestions. Thanks in advance!
-
Problem with Knockout mapping of observable array.I figured it out last night. Actually this was very basic mistake that I was making. I was trying to access an array after setting it to null. I will explain it how. When result were returned that time GridHeaderModel and the IList Cells in it were defined i.e. were not null. That time ko.mapping was able to convert the model and create the model and arrary inside it. But when any ajax request were made wherein noo result was returned and GridHeaderModel was null, obviously the IList Cells was null too. That time ko.mapping did the same, the KO model that it updated, set GridHeaderModel to null too and the observable array Cells inside was no present which is as good as null. Now when I made another ajax request with some records returned, the ko.mapping tried to update the observable array Cells which did not exist (or was set to null) in KO model on the client, it failed. If instead of ajax it were fresh page load everything would have worked. So the solution is not to return any enumeration (those that will get converted to observable array) uninitialized to the client for KO model update. Hence when no record was to be returned I made sure that GridHeaderModel is not null and also made sure that the IList Cells is initialized though it did not contained any element. This fixed the problem. This problem could be explaied with following example.
public class Demo
{
public IList DemoArray;
}public class DemoUser
{
public void UseDemo()
{
var demoInstance = new Demo();
demoInstance.DemoArray.Add("First Element");
}
}Here in the UseDemo() method we have initialized the class instance Demo but the IList DemoArray remains un-initialized. So when we try to access it runtime exception will be thrown. This is what was happening in my case. In first ajax response I was setting the observable array to null i.e. un-initializing it and then in next ajax response I was trying to access it.
-
Problem with Knockout mapping of observable array.I am using knockout (KO) in my MVC project. I create an MVC model (for a grid) on server and pass it to the view. On the view it is serialized and converted into a KO model (using ko.mapping) which in turn is used for binding. That binding is then used in HTML for grid creation. This is how my MVC grid model looks like which in turn gets converted to corresponding KO model by ko.mapping:
public class GridModel
{
/// /// Grid body for the grid.
///
public GridBodyModel GridBodyModel { get; set; }/// /// Grid context. /// public GridContext GridContext { get; set; } /// /// Grid header for the grid. /// public GridHeaderModel GridHeader { get; set; } }
public class GridBodyModel
{
/// /// List of grid body rows.
///
public IList Rows { get; set; }
}public class GridContext
{
/// /// Total number of pages. Read-only.
///
public int TotalPages{ get; set; }
}public class GridHeaderModel
{
/// /// List of grid header cells.
///
public IList Cells { get; set; }
}As it is clear the main model class GridModel is made of following classes which are present as properties: GridBodyModel: Has list of rows to be rendered in the grid body. GridContext: Has total number of pages as a property. It has other properties as well but that is out of scope of this discussion. GridHeaderModel: Has a list of cells that has to be displayed in header of the grid. Then I have this script that will execute on fresh page load.
$(document).ready(function () {
// Apply Knockout view model bindings when document is in ready state.
ko.applyBindings(Global_GridKOModel, document.getElementById("gridMainContainer"));
});// Serialize the server model object. It will be used to create observable model.
Global_GridKOModel = ko.mapping.fromJS (<%= DataFormatter.SerializeToJson(Model) %>);Global_GridKOModel is global javascript variable. Model is the MVC grid model coming from server. A user can perform further search on the page again. I handle this by posting new search criteria via Ajax. On this
-
Embedded image in portable area not showing on deploymentWell due respect to you too, I had already tried all your sane diagnosing methods before I even thought of coming online for help. I just wanted to say that I have tried them already and in-fact I tried them again on your suggestion but it looks like you took it different way and that is not my fault. Just because you have 48 years of experience doesn't mean your suggestion has to be spot on. And so far opening of mind for critical thinking is concerned, point one, I know what I am and don't need certificate from anyone and point two, do you really think you offered suggestion that required critical thinking? And so far being humble is concerned, I always am but not now. This is the worst online reply that I ever gave to anyone and sorry to say but you forced me to do that. I am not sorry at all for replying to you like this. Packer
-
Embedded image in portable area not showing on deploymentNo but it is still not working. Everything looks good but it is still not working. Hints please!
-
Embedded image in portable area not showing on deploymentNo the image is not hard coded with localhost. For the sake of clarity I mentioned it like that. It actually is rendered as "/mysite/login/resource/Images.aw1.png" And as a matter of fact images are being embedded in web app assembly. This can be done by setting image property "Build Action" to "Embedded Resource". I can guarantee that embeding of resource is working fine or else image would not have got rendered on my local too. Moreover I also checked the DLL through a reflector and saw that images were indeed embedded there.
-
Embedded image in portable area not showing on deploymentYes I have checked. They are all good at all time. For Method 1 I used
Url.Resource("Images.aw1.png")
Here the image was located under Images folder which was under the root of Portable area project. URL of the image is rendered as "http://locahost/mysite/login/resource/Images.aw1.png" For Method 2 I used
Url.Content("~/LoginPortableArea/Images/aw1.png")
Here LoginPortableArea is name of the area and images are located in the folder Content/Images which was under the root of portable area project. URL of the image is rendered as "http://localhost/mysite/LoginPortableArea/Images/aw1.png". So we see in both the cases url is correctly generated and the image also gets rendered correctly on localhost of my box but not elsewhere.
-
Embedded image in portable area not showing on deploymentI am using MVC 2 on VS2010 and IIS 7. I created a portable area with some images embedded into it. I tried to create routing rule two ways at the time of portable area registeration. Following are the two ways I tried. Method 1
context.MapRoute("ResourceRoute", "login/resource/{resourceName}",
new { controller = "EmbeddedResource", action = "Index" },
new string[] { "MvcContrib.PortableAreas" });context.MapRoute( "login", "login/{controller}/{action}", new { controller = "login", action = "index" });
RegisterAreaEmbeddedResources();
In this case I tried to access the image using Url.Resource() Method 2
context.MapRoute(
"login",
"login/{controller}/{action}",
new { controller = "login", action = "index" });RegisterDefaultRoutes(context);
RegisterAreaEmbeddedResources();In this case I tried to access the image using Url.Content() Following are scenarios where things are working fine. 1. When I run the application on my local development server (Ctrl + F5). 2. When run application after publishing it on my localhost. 3. When I run the application on different development server (Ctrl + F5), say on my friend's box. But it does not render image (right now I have only images as static resource. No CSS or JS) if I publish on someone else's system, say localhost on my friend's box. Everything else is working fine except for the image rendering. I have tried all possible means to get it rendered in the situation it is failing but all in vain. I need some help here. Anyone please? Thank you in advance!
-
Error mapping table per subclass in Fluent NHibernateWell guys I just got the answer to the above problem. I just missed this mapping in the class SamsungPhoneMap
KeyColumn("SmartPhoneBaseID");
I did not see this being mentioned anywhere, not even the Fluent Nhibernate talks about it. But all's well that ends well, I got the answer at last.
-
Error mapping table per subclass in Fluent NHibernateI will give details of the infrastructure I have built and will talk about the problem in the end. Database table "dbo.SmartPhoneBase" details: Following are the columns in the table.
SmartPhoneBaseID (Identity Primary Key)
Company
PhoneName
RAM
StorageDatabase table "dbo.SamsungPhone" details: Following are the columns in the table.
SamsungPhoneID (Identity Primary Kay)
SmartPhoneBaseID (Foreign Key to dbo.SmartPhoneBase)
AndroidVersion
QualcommProcessorTech
AMOLEDDisplayTechEntity classes for the above tables:
public class SmartPhoneBase
{
public virtual int SmartPhoneBaseID { get; private set; }public virtual string Company { get; set; } public virtual string PhoneName { get; set; } public virtual string RAM { get; set; } public virtual string Storage { get; set; } }
public class SamsungPhone:SmartPhoneBase
{
public virtual string AndroidVersion { get; set; }public virtual string QualcommProcessorTech { get; set; } public virtual string AMOLEDDisplayTech { get; set; } }
Mapping class for the above entity classes:
public class SmartPhoneBaseMap:ClassMap
{
public SmartPhoneBaseMap()
{
Schema("dbo");
Table("SmartPhoneBase");Id(x => x.SmartPhoneBaseID) .Column("SmartPhoneBaseID") .GeneratedBy.Identity(); Map(x => x.Company).Length(100).Not.Nullable(); Map(x => x.PhoneName).Length(100).Not.Nullable(); Map(x => x.RAM).Length(100).Not.Nullable(); Map(x => x.Storage).Length(100).Not.Nullable(); } }
public class SamsungPhoneMap:SubclassMap
{
public SamsungPhoneMap()
{
Schema("dbo");
Table("SamsungPhone");Map(x => x.AndroidVersion).Length(100).Not.Nullable(); Map(x => x.QualcommProcessorTech).Length(100).Not.Nullable(); Map(x => x.AMOLEDDisplayTech).Length(100).Not.Nullable(); } }
Please note following points. 1. For the subclass "SamsungPhone" the primary key is not allowed to be mapped with the method Id() hence I did not keep the property for same reason in the subclass even though its corresponding table "dbo.SamsungPhone" has a primary key.
-
Multiple events on post-backCan you be a bit more elaborate. I did not understand what you want to suggest! :(
-
Multiple events on post-backI our case this will not happen because whole site is javascript dependent. If it is disabled then nothing will work and moreover the site is for Intranet use and user of this site will not have the flexibility to turn the javascript setting of the browser on or off at will. But this question still remains. What if the site were for general public on the Internet? In that case what could be the solution if even javascript could not solve it? Any idea!!
-
Multiple events on post-backThanks for the reply Colin, I tried all possible options including disabling the viewstate as suggested by you but it all failed. I just managed to solve the issue with the help of javascript. Instead of sending the user to the next page via Response.Redirect on the index change of the dropdown, I am now doing the same with the help of simple javascript i.e. window.location.href. Thanks again for the reply, appreciate it!
-
Multiple events on post-backI did the same but it is not working......looks like the browser is remembering the previous state of the page and so is causing the previous event to be raised in addition the present event..... I think I have to take help of javascript. Thank for the reply
-
Multiple events on post-backI am facing a unique problem (looks unique to me at least). I have a dropdown whose auto-postback is enabled. User can select a value from the dropdown to go to another page. But when the user comes back to original page by clicking the back button on the browser and clicks any button then on the post-back caused by the button, first the "SelectedIndexChanged" event handler of that dropdown is called then the "Click" event handler of this button is called. Hope I have explained the problem clearly. Can anyone tell me what's going wrong and how to solve the issue?
-
File sharing between VMware and hostThe network is already set I guess on the host. So am I supposed to use Subnet : 192.168.175.0 (Refer my first post). How do I use it. Bcz on the guest nothing is visible. Cant see any network on the guest. Or is it that I am supposed to create a new network? How do I do it? Please bear with me as I am unknown to these things
modified on Friday, September 19, 2008 6:06 AM
-
File sharing between VMware and hostI don't know about the version 6 but version 5 do not have such option .... can you suggest a way out?? I hope the info I have given is useful to think about the problem..!!
-
File sharing between VMware and hostI hope this is the best place to ask this question. Few days back I installed VMWare workstation 5 on Vista Home Basic as host. I have installed Windows XP as guest OS in the VMWare. While installing I had set the network connection as "NAT : Share host's IP Address". I guess it is because of this I am able to access Internet from the guest OS. I want to share files between the host and the guest OS. Can someone help with this? Here are some info in case it is required. Virtual network settings summary VMnet0 (bridged) :- Bridged to automatically chosen adapter. Subnet : 255.255.255.2 VMnet1 (Host-only) :- A private network shared with host. Subnet : 192.168.175.0 DHCP : Enabled VMnet8 (NAT) :- Used to share host's IP address. Subnet : 192.168.240.0 DHCP : Enabled
-
Creating and executing DTS packageHey no problem man..... but thanks for the reply anyways