Mvc Ajax How To Pass The Id As Well To The Controller
Mar 15, 2011[code]....
i am having problem passing in passing the url id to the controller with the form . how can i do that ?
[code]....
i am having problem passing in passing the url id to the controller with the form . how can i do that ?
I have a simple model where a Person has Gifts. I have a view which is a list of Gifts belonging to one Person.
My problem is with the Create action for a new Gift. I want it to default to the PersonID that we are already viewing the list of Gifts for. I tried simply passing the last PersonID (they are all the same)
Html.ActionLink("Create New", "Create", new { id = Model.Last().PersonID }) which works fine if there is already at least one Gift for that person but if this is the first Gift I don't have a value.
My Gift List controller knows the PersonID I want to pass but the view doesn't.
How do I pass this PersonID from my Gift List controller to my Gift Create controller via the Gift List view? Or is there a better way to do this?
I have a drop down where I want to pass the selected value I selected to the controller. How do I accomplish this?
View 2 RepliesI have an action:
public ActionResult Details(int? aaaID, int? bbbID)
and I am trying to route the url http://..../controller/aaa/23432 to action Details.
routes.MapRoute( "controller", // Route name "controller/aaa/{id}", // URL with parameters new { controller = "controller", action = "Details", lblID = UrlParameter.Optional } // Parameter defaults);However, the aaaID of function Details also get a null value?
In my ASP MVC app I have an asp: DropDownList control that has a source of a Linq data class. The values in the list are getting set fine, but when I select one, and then click on an Html.ActionLink, and pass control back to my controller, I'm not sure how to fetch the value that was selected from the DropDownList.
View 1 RepliesHow Can I Pass SelectList into Controller?
here is my code
[Code]....
I am trying to get this functionality on my jokes website:
www.mysite.com/category/bar
To get all the bar jokes ..etc
The way I have my route right now is:
{controller}/{action}/{id}
which means I have to type:
www.mysite.com/category/index/bar
the problem is that even with that, the string parameter "bar" isn't being acknowledged ! ( I know from debugging). Here is my Index action in the Category controller:
[Code]....
I have some textboxes and a table of data created client side that I want pass to a controller as JSON.
I want to use Jquery to enumerate the table.
Assume I have 2 textboxes called name and age. Assume a table with 2 columns. one column with class called phonetype and one column class called phonenumber.
So how do construct the JSON from this?
i have a view /categoria/index
[Code]....
i am trying to call the action from /imovel/index
with an id
but the thing is that i am getting null
[Code]....
Iam trying to pass data from my controller, and put it into the variable in JS script. I have done it before and it worked perfectly, thats why this one puzzles me even more.
Here is my code of the controller:
[Code]....
In chrome I also get an error "Uncaught SyntaxError: Unexpected token ILLEGAL". I am pretty sure it is the same I use for my other project and that one works just great so I really dont know what is wrong.
I've a controller with different actions that calls the DB code and return result. I want to pass the value of text box to different actions in controller.
How to do it? I know that, I can pass values by using form. But, I don't to know how to call different actions in controller from single view.
This may seem simple to a seasoned coder, but I'm all wet-eared and new to MVC, and trying to wrap my head around it is driving me nuts. I have completed the Nerd Dinner and MVC Music Store tutorials, and seem to be grasping the basics... Well, sort of... It just seems that every new idea I have requires hours of searching with Google.
As it stands at the moment, I have a static DateTime field that is populated by using DateTime.Now. What I need to implement is a master TextBox (JQueryUI DatePicker) at the top of the View that will enable the user to overwrite said DateTime.Now if required.
Here is a hypothetical situation:
Controller
[Code]....
Site.Master
[Code]....
View
[Code]....
I thought of using a variable to override the default date if the user selects a master date, but can't figure out how to implement it.
I can get it to work if I use a static string, like so:
[Code]....
Is there any way to pass the value of the master datepicker (txtDateTime) from the View back to the Controller? I've heard mention of TempData, but can't seem to find a similar scenario.
I'm sure I'm just missing something really obvious, so if anyone could explain it to me really s-l-o-w-l-y, that would be cool.
I'm praying that this isn't another of those situations where "MVC doesn't work that way" or "It needs more cowbell", 'cause then I'll pack it all in and go play WoW D:
How to pass the textbox value to my controller there is no form and post method in the viewpage.I have taken one input type textbox which is not bind with my model.I need to access that value to controller
View 13 RepliesI have this controller:
public ActionResult Details(String UserName)
{
using (var db = new MatchGamingEntities())
{
var Users = from m in db.Users
join m2 in db.MyProfiles on m.UserId equals m2.UserId
where m.UserName == UserName
select new UserViewModel
{
UserName = m.UserName,
LastActivityDate = m.LastActivityDate,
Address = m2.Address,
City = m2.City,
State = m2.State,
Zip = m2.Zip
};
return View(Users.SingleOrDefault());
}
}
I type in the url Profiles/Details/hello, but it does not work, if I do Profiles/Details?UserName=hello then it works. I have another ActionResult just like this except taking in an int id as parameter and it works fine with the first url format.
Consider the following data
<xml>
<id>10</id>
<value1>15<value1>
</xml>
I need to use this data as an input to ajax request. For eg. consider a dropdownlist change event, I need to pass these values to the controller.
sample code
//dropdown change event
$("#TestReqID").change(function() {
var id = 10;
var testResults = "abc";
var inXML = "<xml>";
inXML = inXML + "<id>" + id + "</id>";
inXML = inXML + "<value1>" + testResults + "</value1>";
inXML = inXML + "</xml>"
$.getJSON("/Home/UpdateTest/Json/" + inXML, function(data) {
//success code goes here
});
});
in HomeController
public ActionResult UpdateTest(string obj)
{
if (HttpContext.Request.IsAjaxRequest())
{
/*
Need to parse data in "obj" from ajax request
*/
IPTests test = _service.GetIPTest(Convert.ToInt32(id));
return new JsonResult { Data = new { ipTestId = "0", testResults = "" } };
}
return View(test);
}
instead of xml string is it possible to use javascript object like
[Code]....
I want to pass a message from the controller to a view using Viewdata. Here is my code:
public ActionResult Create(FormCollection createPage)
{
try
{
......................
ViewData["Message"] = "Success - rec added!!!!" ;
return RedirectToAction("Index");
}
catch (Exception e)
{
ViewData["Message"] = "Exception: " + e.ToString();
return RedirectToAction("Index");
}
On my View I have:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>::><%: ViewData["Message"] %><::</h2>
<h3>==><%= ViewData["Message"] %><==</h3>
<p>
This is Index.aspx page in Controller folder
</p>
</asp:Content>
I am getting result with empty ViewData["Message"]
I am creating an instance of a business layer in the constructor of my Controller and then I am passing this to my view model like this;
[Code]....
The problem is when I make a post from the view with the viewmodel, I get an error that MyViewModel doesn't have a parameterless constructor defined, and I don't want it to have. Is there anyway I can pass the _businessLayer variable from the controller to the viewmodel when it's constructed "on the fly" in a method like this;
[Code]....
Maybe by using a custom model binder?
My view has a number of rows.
Each row has a drop down, a text box and an "add" link. I'd like for someone to select something in the drop down, edit something in the text box and pass that information to an Action in the Controller.
I know i can do something like this:
[Code]....
[Code]....
Which is kind of gross - id like to do just call one action, that passes the selected drop down value, the textbox value and call just the one action, is it possible to do something like this:
[Code]....
Where i pass the Dropdownlist selection and the textbox value to my controller specifically
In asp.net mvc3, I've got a few local variables in one of the controller, is there any neat way to pass all these variables to view? Something like "locals()" in python?
View 1 RepliesHere is my ASP code:
<asp:GridView ID="WagerTable" runat="server" AutoGenerateColumns="False" CssClass="basix" >
<columns>
<asp:BoundField DataField="GameName" HeaderText="Game Name" />
<asp:BoundField DataField="Amount" HeaderText="Amount" />
<asp:BoundField DataField="Comment" HeaderText="Comment" />
<asp:BoundField DataField="CreateTime" HeaderText="Create Time" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" Text="Accept" OnClick="AcceptWager" ID="AcceptButton" />
</ItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
This is my code behind:
protected void Page_Load(object sender, EventArgs e)
{
AccountManager accManager = new AccountManager();
MembershipUser newUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
Guid UserId = (Guid)newUser.ProviderUserKey;
String myConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlDataReader reader;
using (SqlConnection myConnection = new SqlConnection(myConnectionString))
{
myConnection.Open();
String selectSql = "SELECT * FROM aspnet_Wagers INNER JOIN aspnet_Games ON aspnet_Wagers.GameId = aspnet_Games.GameId";
SqlCommand myCommand = new SqlCommand(selectSql, myConnection);
myCommand.Parameters.AddWithValue("@UserId", UserId);
reader = myCommand.ExecuteReader();
WagerTable.DataSource = reader;
WagerTable.DataBind();
myConnection.Close();
}
}
protected void AcceptWager()
{
}
I want to be able to have it so that each LinkButton can pass through an ID from the database as an parameter into the AcceptWager function and then I will do with it from there. The sql column for the ID is WagerId. It is returned in that query that i execute, so it is already in the reader.
My query is somehow related to passing the id values as parameters in MapRoute on RegisteredRoute method
routes.MapRoute("MachineGroupList:, PhysicalMachine/ListGroupMachine/{used}/Page/{page}", new {controller="PhysicalMachine", action="ListGroupMachine",id="XNA"});
How can i use {used} value in id ?
My Page have:
<%: Html.RouteLink("<<<", "MachineGroupList", new{used=Model.UsedBy,page=(Model.PageIndex-1),id=Model.UsedBy})%>
My controller for this Action is:
public ActionResult ListGroupMachine(string id, int page=0)
{
....
}
Everytime I call this Action the Id should be of groupBy column; over here it is 'Used' First time I have called this Action from <%html.ActionLink("Machine","ListGroupMachine", new {id=Model.UsedBy})%> But in my Html.RouteLink the id object is not identified in MapRoute method...
How to pass model bind collection from one controller to another?
I have this model class,
Public Class Sports
Private _SportsID As Integer
Private _SportsName As String
[Code]....
how to pass values from ascx page contains [ 3 textboxes] to controller
View 2 Replies[Code]....
for List<AnswerInfo>,
[Code]....
now, what i want to do is to place few textboxes on a view that allow users to input the Answer Text. after click the submit button. i want List<AnswerInfo> which contains the Text information pass to the controller. can anyone tell me how to do it?
How Can I Pass data(not the part of model) to Controller from View? View Code
[Code]....