MVC :: Passing Entire Object Rather Than Just ID?
Feb 22, 2010
I am working on a project where I have a form to create a new user. In that form we have a dropdown list that is populated from another table called ElectricCompanies. The Users table and ElectricCompanies tables are related (each User can only have one electric company, but electric companies can have multiple users). I am having trouble getting the Electric Company object to pass into the Users table. The Users table wants it to be passed as a object of the table ElectricCompanies, but right now it only passes the ID.
This is the code from the UserController under the Edit that I used to populate the ElectricCompany dropdown list:
Dim eleccomp = (From p
In _DB.ElectricCompanySet Select p)
ViewData("ElecComp") = New SelectList(eleccomp,
"ID", "Name")
Is there a way to pass an entire object rather than just the ID?
View 2 Replies
Similar Messages:
Mar 16, 2013
I m having a grid view on web3.aspx page
I am having another page web9.aspx page with a button on it.
On the click of this button i want to display the grid view present on web3.aspx.
View 1 Replies
Mar 23, 2013
i want to pass an entire grid view from once page to another without using web user control.
how can we create an instance of the grid view on some other page.
View 1 Replies
Jun 16, 2010
Using an objectdatasource I would like to pass an entire DataItem to a function, within a databinding statement. I have found a way that works, but I don't like the look of it. ;-)
Lets say I have a class called "People", with two properties "firstName" and "lastName". I have an objectdatasource which returns a list of "People", and I use that to populate a Repeater.
I also have a function called "GetFullName", which takes a "People" object as it's parameter, and returns the lastname and firstname with a comma between them.
In the ItemTemplate of the repeater, I could do this:
<%# GetFullName(CType(Container, RepeaterItem).DataItem) %>
-but it looks like such a hack. (Doesn't it..? Maybe it's just me.)
View 3 Replies
Apr 7, 2010
My problem is to save or pass a table object and use it in other page/controller.
I want to pass the object through pages to save just in the last STEP.
My controller:
[Code]....
I need to save the "d" object to use(save to database) just in other page/controller.
View 8 Replies
Mar 11, 2010
I have a search page which generates a GridView of results based on the search terms entered by the user. One of the columns in GridView is called a DOI (Document Object Itentifier). This DOI is used to find academic papers through [URL] when a user enters a DOI string. What I would like to do is redirect the user to the relevant webpage when they have selected the DOI in the GridView, however, the url for this page is always different. In the page, I have formatted the form tag like so: [URL] and in my GridView, I have formatted the row that I wish to have hyperlinked like so:
<asp:ButtonField DataTextField="DOI" HeaderText="DOI" CommandName="d"/>
Then, in my C# codebehind, I have the following event which aims to redirect the user to the required page, based on the tag they have selected:
switch (e.CommandName)
{
case "d":
searchResult.Attributes.Add("onchange", "window.open [URL]
break;
}
I don't think this code above makes any difference though as the form tag is already specifying the redirected url, nor do I think this task can be done with a html <table> object, as it only accepts static data, rather than a result set generated from a database, which is what I'm doing. I have also looked at the following post as a guide to this type of problem but, taking account of what it said didn't allow me to solve this problem completely. GridView with DDL and selected value
View 1 Replies
Mar 23, 2011
I've implemented a custom ASP.net membership provider to deal with forms authentication. The custom provider uses a custom User object for authentication and authorization. I was wondering If I can pass this object to each WCF call without adding it to the parameters list?
View 2 Replies
Apr 9, 2010
I have the following ActionResult() method:
[Code]....
The method is called once the <form> is submitted. If the validation is good, it moves on to create a new user Once the new user is created, I want to redirect the user to a "ThankYou" page passing along the newly created user (object). The TempData["User"] trick seems to work like a charm! Then inside my ThankYou ActionResult() I do the following:
[Code]....
The problem I have is once the user has been redirected to the "ThankYou" page. If he decides to refresh (F5) his browser, the value in the TempData is lost.
What are my possibilities to overcome this issue?
Instead of passing an entire object to my "ThankYou" page, I initially thought of passing the ID of the newly created user and re-query my database to get the object.
The only problem is that the ID will be seen in the QueryString allowing the user to simply change the ID value and try to find other users...
Is my only other alternative to simply place the user object inside a Session? Is that my only other option?
View 6 Replies
Nov 24, 2010
Working with asynchronous postback. onclick of "OK" button i m fetching data from DB and it is in dataset without page-refresh.
DataSet ds = new DataSet();
ds = SearchResult.GetDataTable("dbo.spGetEmployeeDetails", thisConnection, searchItem);
1. How can i pass this dataset object to javascript as responseText?
2. In javascript i have to create table(create rows depending on number of nodes in dataset) and display responseText in aspx.
View 1 Replies
Feb 17, 2010
How do it do this. I have this at the moment
[Code]....
[Code]....
This takes a large INT and returns 4 strings from the BO structure HotelFacilities
If I set the private from string to AccommodationBO.HotelFacilities it is fine
If I set the public from string to AccommodationBO.HotelFacilities it moans because the Set section of the private property is wrong. But the set would be an INt.
All I actually want to do, is populate the BO Structure and passit to the user control using a property in the user control code behind. Is this possible ??
Dim jim As New GetAccommodationPricesBLL
View 1 Replies
Mar 26, 2010
ss a list of objects as a paramter in an actionlinkAt the moment when I try to do this the list is always empty by the time it reaches the controller!
<%= Url.Action("ActionName", new { list = Model.ListOfObjects}) %>
public ActionResult ActionName(List<Object> list)
{
//Do stuff
}
View 3 Replies
Mar 11, 2011
[DataContract]
public class UserCertification
{
...
}
[DataContract]
public class UserPhone
{
...
}
[code]...
View 2 Replies
Feb 16, 2010
I am trying to implement the same code that was mentioned in this questionCurrently I have the following code:
var pagePath = window.location.pathname;
var paramList = '';
if (paramArray.length > 0) {
[code]...
View 1 Replies
Jun 4, 2010
I'm trying to create a JSON object on client-side and pass to a server-side function. Then instantiate it on server-side using JSON string representation.
So I create jSON object on client-side
var myJsonObject = {
"arg1": var1,
"arg2": var2
}
and pass it in to
WebForm_DoCallback(controlID, myJsonObject , null, null, null, true);
When I try to retrieve this JSON object on server-size I get as a string representation of JSON [object Object]
So in following server-side function, the argument value is [object Object]
public void RaiseCallbackEvent(string jsonObj)
I was expecting a string representation of JSON object. How do I pass in a string representation?
View 1 Replies
Mar 4, 2011
I have the following to get the Json abject passed from the controller and populate the various textboxes in the view. However, nothing is happening even though controller is passing a valid Json object. What is wrong with this code?
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var url = '<%=Url.Action("DropDownChange") %>';
$("#vendorID").change(function() {
var selectedID = $(this).val();
if (selectedID != "New Vendor Id") {
//$.post('Url.Action("DropDownChange","Refunds")', function(result) {
$.post(url, { dropdownValue: selectedID }, function(result) {
alert(selectedID);
$("#name").val(result.Name);
$("#city").val(result.City);
$("#contact").val(result.Contact);
$("#address2").val(result.Address2);
$("#address1").val(result.Address1);
$("#state").val(result.State);
$("#zip").val(result.Zip);
});
}
});
});
This is the code in my controller;
public JsonResult DropDownChange(string dropdownValue)
// This action method gets called via an ajax request
{
if (dropdownValue != null && Request.IsAjaxRequest() == true)
{
paymentApplicationRefund =
cPaymentRepository.PayableEntity(dropdownValue);
paymentApplicationRefund.Address1.Trim();
paymentApplicationRefund.Address2.Trim();
paymentApplicationRefund.Name.Trim();
paymentApplicationRefund.City.Trim();
paymentApplicationRefund.Contact.Trim();
paymentApplicationRefund.State.Trim();
paymentApplicationRefund.Zip.Trim();
return Json(paymentApplicationRefund,"application/json");
}
else
{
return null;
}
}
View 3 Replies
Nov 1, 2010
I am trying to send json data from view to controller action. But the issue is the data is not populating in the action parameter List<Score>.
View Model:
public class Score
{
public int QuestionId { get; set; }
public int PrevAnswerId { get; set; }
public int CurrAnswerId { get; set; }
public string CurrAnswerName { get; set; }
}
Json Data look like:
[
{QuestionId:1, PrevAnswerId:3, CurrAnswerId:3, CurrAnswerName:'Known to Broker'},
{QuestionId:2, PrevAnswerId:7, CurrAnswerId:7, CurrAnswerName:'Completed'},
{QuestionId:3, PrevAnswerId:10, CurrAnswerId:10, CurrAnswerName:'Report'}
]
On window load, I will construct the Json object using "eval()" function and do some operation in the data before its save. On Save Click, I will call the action through the ajax call.
$.ajax({
url: url,
type: "GET",
dataType: 'json',
data: {score: ScoreJson},
contentType: "application/json; charset=utf-8",
success: function () {
alert("succes");
},
error: function () {
alert("error...");
} });
Action:
public ActionResult SaveScore(List<Score> score)
{
// do something...
}
But here score comming as collection of 3 elements with zero(for interger property)/null(for string property) values. When I checked in the request I found the data in "parama" property like.
"Score%5b0%5d%5bQuestionId%5d=1 &Score%5b0%5d%5bPrevAnswerId%5d=3 &Score%5b0%5d%5bCurrAnswerId%5d=3 &Score%5b0%5d%5bCurrAnswerName%5d=Known+to+broker&
Score%5b1%5d%5bQuestionId%5d=2 &Score%5b1%5d%5bPrevAnswerId%5d=7 &Score%5b1%5d%5bCurrAnswerId%5d=7 &Score%5b1%5d%5bCurrAnswerName%5d=Completed&
Score%5b2%5d%5bQuestionId%5d=3 &Score%5b2%5d%5bPrevAnswerId%5d=10 &Score%5b2%5d%5bCurrAnswerId%5d=10 &Score%5b2%5d%5bCurrAnswerName%5d=Travelers+Report&".
But I am not sure why it is not getting populated in the score list. One full day I spent for this issue but till now I didnt find the solution for this issue.
View 4 Replies
Apr 9, 2010
We need to create a simple web service in ASP.NET that can be called from PHP or other languages. This in turn will be used to update records in a database for an item submission.
The core part is fairly simple, we have a base set of fields for the object - first name, last name, birth date, city, etc. In addition however we need to accept a list of items associated with that object that can range from 0-n.
Jan 1 2009, ABC
May 1 2010, 123
Jun 30 2010, XXXXX
What would be the best way to structure this so it can be easily passed to the ASP.NET web service and processed as a single call for the entire object? Would passing the list of items as a single delimted string be a wise approach? Ex: Jan 1 2009, ABC|May 1 2010, 123|Jun 30 2010, XXXXX
View 1 Replies
May 11, 2010
I have a custom class declared as follows (in vb.net)
<Serializable()> _ Public
Class NumInfo Public n As String
Public f As Integer Public fc As
char() Public t As Integer
[Code]....
What am I doing wrong? For the record I tried replacing char() with string to see if it was the array causing problems but that didn't help either. I'm fairly new to web services. I tried replacing the custom object parameter with a primitive parameter just to check how things worked and it rendered a page with an input field and invoke button.
View 1 Replies
May 18, 2010
I have a variable element in which I am passing a div and replacing object {0} with the actual control string I am getting. Here is my code.
[Code]....
string.Format(element, entities.ThumbnailImage);
In entities.ThumbNailImage I get the following image control string which I am trying to pasre, here is the string.
<img src='http://edgesuite.net/image/media/150_SOAK594002518_3000.jpg' id='imgrichFx8483' alt='' class='productClass' runat='server'/>
But string.Format gives me error, Input string was not in a correct format.
View 8 Replies
Mar 31, 2010
I am calling a WebMethod from this code:
if($(this).attr("checked")) {
..
MyWebMethod(variable1, variable2, onSuccessFunction);
}
The MyWebMethod returns an integer, and I want to set $(this).attr("id") of the jQuery object above to the returned integer. Basically, I'm trying to do the equivalent of an MVC Ajax.ActionLink...AjaxOptions {UpdateTargetID =...} However, I can't figure out how to get both a reference to $(this) as well as the returned value. For example, if I do:
MyWebMethod(variable1, variable2, onSuccessFunction($(this)));
I can succesfully manipulate the jQuery object, but obviously it doesn't have the return value from the MyWebMethod. Alternatively, the first code block with a method signature of onSuccessFunction(returnValue) has the correct return value from MyWebMethod, but no concept of the jQuery object I'm looking for. Am I going about this all wrong?
View 1 Replies
Feb 11, 2011
How would I pass an Object or Array to a function using the ICallBackEventHandler (RaisCallbackEvent)? It allows for a string argument only, if you change it to another datatype it error out. Sample Below...
[Code]....
[Code]....
View 6 Replies
Mar 30, 2010
I'm trying to use an ObjectDataSource's SelectMethod() to retrieve a result set from a sql server database to populate a data table with various stored procs that have any given number of parameters. My approach is to pass an object which contains the stored proc name and information about its parameters into the SelectMethod(). My issue is that I don't know how to actually set the default value. Here is the code I have so far:
ObjectDataSource1.DataObjectTypeName = "WebApplication1.Children";
ObjectDataSource1.TypeName = "WebApplication1.Children";
ObjectDataSource1.SelectMethod = "Select";
Parameter odsParameter = new Parameter() { Name = "storedProc", Type = TypeCode.Object };
// How do you set the default value to reference an object?
ObjectDataSource1.SelectParameters.Add(odsParameter);
namespace WebApplication1
{
public class Children
{
public DataTable Select(object storedProc)
{
// do stuff here and get db values.
}
}
}
The default value of a Parameter object is a string type. Does anyone know how to set the default value with an object or how I can pass an object into the SelectMethod?
View 2 Replies
Dec 13, 2010
I have a shared module in an asp.net web app which gets various information about a group or user. Since the Iuser account on the web does not have enough rights to query the AD, I need to supply an appropriate userid and passcode for the directoryentry in the shared code. Since my credentials so the have the appropriate rights to query the AD I like to impersonate myself(user.identity). This works fine for a webpage, but I can't pass the user.identity object to shared code. I get an error. Is there a way to pass the user.identity object to a shared function in another module?
View 1 Replies
Nov 16, 2010
I have something like this
[code]....
it works fine, but I need to create a user object by passing Guid like this
MembershipUser user = Membership.GetUser(new Guid(userId));
what may be the cause. it woks fine from C# code behind.
View 1 Replies
Apr 16, 2010
I have a user control inside a repeater. I am binding a collection of objects to the repeater.
My user control has a public property to retrieve the object (setobject)
How do i pass each object through to the user control and not just the object property value? What is the syntax to do this?
[code]....
View 1 Replies