Passing Data From Usercontrol To Controller?
Jun 1, 2010
I am new to MVC, and trying something and got stuck somewhere in between.I have a user control there I have three textbox html type(ID, Lastname, firstname) and a submit buttom. I set the button like
<input type="button" value="Search"
onclick="location.href='<%= Url.Action("action", "controller") %>'" />
I have called this usercontrol on some view through
<%= Html.Partial("ucName") %>
Now on pressing that button(on user control) I need to pass the data from these textboxes to controller again to some specific action(Http Post action). By using this data I want to do some database interaction and storing the result in a dataset and pass this data set to same view again to show up in some Grid.I know the first part in conventional Asp.net can be done by raising the event through delegate but don't know how to do that in MVC.
View 2 Replies
Similar Messages:
Nov 16, 2010
I have setup an httppost that sends a string into my controller, searches for some results using linq, and then sends the results to a view. In debug stepping through the code I can see the data that I am looking for being passed into the return view statement, but the page just appears to refresh (it doesn't render the view as expected with the result). why my controller fails to redender the view? (note: I didn't include the view because I can send a ToList() to it without an issue. For example, return View(_entities.Persons.ToList());
[HttpPost]
public ActionResult RenderSearch(string usersearchtext)
{
if (usersearchtext != null)
{
var search_results = from s in _entities.Persons
where s.Description.Contains(usersearchtext)
select s;
return View("SearchResult", search_results.ToList());
}
else
{
throw new NotImplementedException();
}
}
View 8 Replies
Apr 22, 2010
I have a dictionary I'm passing to a View. I want to be able to pass the values of that dictionary back to a Controller action from this same View. Is there anyway this can be accomplished without using a form? The situation is that I need to be able to pass these back to a controller action that is called when a user clicks an ActionLink from the View, and in my experience an ActionLink cannot be used to submit a values of a form, i.e. I've only been able to submit values of a form using the form's submit button. Unless there's a way to use an ActionLink to submit values in a form.Controller Action passes Dictionary to Controller in ViewData:
public ActionResult ModifyNewCrossListing(FormCollection form)
{
Dictionary<int, string> prefixlist = new Dictionary<int, String>();
[code]...
View 1 Replies
Jul 14, 2010
I have a table with a ID, CodeID,LibelleID field. I am using oracle connection. i want to display in a drop downlist (textfield) CodeID+LibelleID for exemple "100-SalaryBase" where CodeID=100 and LibelleID="SalaryBase" is it possible to obtain it if the user selects an element from the dropdownlist how to post both the codeID and ID to the controller
View 4 Replies
Sep 23, 2010
I have following situation - I am pasing user info object from Controller to View. It contains GUID UserID, which i dont want to be seen on page. So I removed every Html.LabelFor(model => model.UserID), Html.TextBoxFor(model => model.UserID) etc... from generated View source. And because of this when Html.BeginForm() returns that object back to Controller all values is there but UserID is lost??
If I leave Html.LabelFor(model => model.UserID), Html.TextBoxFor(model => model.UserID) etc.. in View everything is fine. But I dont want to show UserID? Where is the problem here?
<%= Html.LabelFor(model => model.C__User_Id) %>
View 6 Replies
Dec 13, 2010
I am trying to pass a view model of mine, which has multiple list in it, to my view. Then in my view i need to edit the different list. Then on my post i need to save the edits. Although, when i pass my viewmodel back to my post, it is empty! Can somebody explain what i am doing wrong? Controller
[Code]....
here is my View
[Code]....
NewsViewModel
[Code]....
View 2 Replies
Apr 29, 2010
I am getting started with Ap.net MVC. For that i chose to practice it by build an application. Im using MVC 2 and Linq To SQL, and i would like to passing another Query to the view. For example, i have this:
[Code]....
So i would like to pass data1 and data2 to the View. I can use return View(data1), but the View function accept just one data. So what technique i can use to pass the tow data to the view
View 5 Replies
Feb 3, 2010
Basically, I have an HTML Form and would want to pass the data from the form to n asp.net mvc controller, then the controller would return an XML for client side manipulation.
Here is my initial code:
[Code]....
When I run and debug, I get a message that says "attr(..) is null or not an object. I am still trying to learn web development using ASP.NET MVC.
View 3 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
Aug 23, 2010
I am getting an null referance on file, what am I doing wrong.
<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
<%: Html.ValidationSummary(true) %>
<%: Html.Label("height") %>
<%: Html.TextBox("height") %>
<%: Html.Label("width") %>
<%: Html.TextBox("width") %>
<%: Html.Label("Media") %>
<input type="file" id="Media" name="Media" />
<input type="submit" name="btnAdd" value="Add" />
<% Html.EndForm(); %>
controller code:
[HttpPost]
public ActionResult AddMedia(Guid id, HttpPostedFileBase file, FormCollection collection)
{
string mimeType = file.ContentType; // Null Exception here ....
View 2 Replies
Apr 21, 2010
when i worked in .NET 1.1 i used to pass parameters to user control using the method- (if the name of the usercontrol is "tables")
dim r As tables =
CType(Page.LoadControl("~/usercontrol/tables.ascx"), tables)
and calling public property of the usercontrols.
the problem is that i can't the way to do it in 2008 ver of .NET, it is not recognize the usercontrol.... how can i pass parameters to the usercontrol in run time?
View 10 Replies
Sep 2, 2010
I would like to pass List<SelectListItem> (not selected item but the whole "List" object) back to controller.
for example in my GET controller i would have this
ViewData["list"] = some select list from repository;
then on post I would like to get the list back from view..pretty much i'm trying to use ViewData["list"] as storage..this way I would use ajax to remove or add items to/from the list.
View 10 Replies
Jun 12, 2010
When user click on <a> tag i want to pass the id value to controller
View 1 Replies
Mar 23, 2010
i am using this code for render view
[Code]....
and this code for action Method
[Code]....
i can access the value text box by AgencyID but if i clicked on Second record AgencyID returns first recode id totally AgencyID returns the first record id.
View 4 Replies
Dec 21, 2010
in my asp.net mark up I have a foreach loop that iterates through a simple list. In this foreach loop I am adding a new user control and attempting to pass in the value from the loop. However, this value just wont budge and get inside that damn control!
<%foreach (userInfo i in this.items)
{ %>
<uc1:ItemControl ID="ItemControl" runat="server" UserID='<%#Eval("userID") %>'/>
<%} %>
userID is a public property in the control, when it goes to set, the value is just literally :
<%#Eval("userID") %>. I've tried #Bind and =Value but nothing seems to work.
View 2 Replies
Jun 15, 2010
My method looks like:
public static RedirectToResult(Controller controller, ...)
{
}
when I do:
controller.
I don't see RedirectToAction, how come?
I get RedirectToAction from within the controller's action, but not when I pass the controller as a parameter to another classes method.
View 3 Replies
Oct 6, 2010
I've been going at this for several hours and I simply cannot find the solution.
I want to get some data from my user. So first, I use a controller to create a view which receives a Model:
[code]...
The rest of this controller does not matter since no matter what I do, the count attribute of Request.Files (or Request.Files.Keys) remains 0. I simply can't find a way to pass the files from the form (the Model passes just fine).
View 2 Replies
Jan 20, 2010
I'm having problems passing values from the controller to the view. I created a boolean variable to use as a flag and want the view to render some html based on whether its true or false.
Unfortunately ViewData doesn't look like it can pass boolean values. I should be able to pass any datatype to a view (string, int, bool, etc...)
View 16 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 7, 2011
I have the following javascript. Problem is if I enter one row in the table "ingredients" but I am getting 2 rows in the resulting pass to controller action after seralising into my C# object. But the second object is null? I checked the javascript and the variable "cnt" is 1 not 2. Why would that be?
[code]
$("#Save").click(function () {
var title = $("#recipetitle").val();
var category = $("#category").val();
var preptime = $("#prepTime").val();
var preptimeperiod = $("#lstPrepTime").val();
var cooktime = $("#cookTime").val();
var cooktimeperiod = $("#lstCookTime").val();
var rating = $("#rating").val();
var method = $("#method").val();
var jsontext = '{ "RecipeTitle": "' + title + '",';
jsontext += '"CategoryID":' + category + ',';
jsontext += '"PrepTime":' + preptime + ',';
jsontext += '"PrepTimePeriod":"' + preptimeperiod + '",';
jsontext += '"CookTime":' + cooktime + ',';
jsontext += '"CookTimePeriod":"' + cooktimeperiod + '",';
jsontext += '"Rating":' + rating + ',';
jsontext += '"Method":"' + method + '",';....................
View 1 Replies
Mar 24, 2011
I am working on Tenant module that has to display following fileds, Tenant Id, Tenant Desc, Contact Person, Contact Phone. In the DB, these are designed as two separate tables - Tenant and Contact. Tenant table has Tenant Id, tenant Desc and Contact Id . Contact table has all the contact related properties. I am using EF as DAL.
To make my system loosely coupled, I have created a repository pattern to talk to EF entities. Also, for validation I am using service layer.
My repository layer has two interfaces and classes corresponding to Tenant and Contact.
public interface ITenantRepository : IRepository<Tenant> // IRepository<T> is a generic interface for CRUD operations
{
Tenant Get(int id);
IEnumerable<Tenanr> List() ;
[Code]....
View 4 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
May 3, 2010
i want load a usercontrol dynamically and pass a string to it ho do i do it..
View 3 Replies
Jun 11, 2010
i am creating a generalize deleteusercontrol , my aim is that on the listing page where all the records are listed when the delete is pressed i want to display the acknowledgment on the same page up the list. I had little idea to do thatq1) first of all where will i place my deleteusercontrol(in the shared folder?). q2) on and off the deleteusercontrol as the acknowledgment will not be there all the time how would i be doing that on delete press. i don't want to pass any data in the querystring.q3)how would i be passing the records list id and listname to the general deleteusercontrol as it would be same for all the listing
View 1 Replies
Aug 5, 2010
I need to pass a list of Entity Objects from Controller to View but not put it in the Model context. It is the users homepage, but I am putting a list of alerts on the users home page(somewhat like facebook). So I need the User Context as the Model I pass but need to pass the Alert model as well so I can show the list of alerts.. How would I do that? The code below is what I have so far..
UserController
[Code]....
UserRepository
[Code]....
View 1 Replies