MVC :: Passing A Checkbox Value Via An Action Link?
Jan 12, 2011
I have an action link that I use to pass values to a controller using this statement:
<%: Html.ActionLink("Addition 1 to 10", "CreatePdf", "Pdf", new { id = 32, stOperation = "Add", stNumbers = "10" }, null)%>
So when a user clicks on the above link the controller CreatePDF is called with the parameters of id, stOperation, and stNumbers. I then use these three parameters to return a pdf document to the user.I also have a checkbox on the html page as defined by:
<%: Html.CheckBox("chkAnswers", false) %>
My question is how to pass the value of this checkbox in the above HTML.ActionLink? I have a tutorial on using the submit button to submit an entire form and the associated data. However I do not want the user to have to click a button. Instead I'd like return the value of the checkbox in the action link but I'm not sure how to do this. I want something like:
%: Html.ActionLink("Addition 1 to 10", "CreatePdf", "Pdf", new { id = 32, stOperation = "Add", stNumbers = "10", checkboxValue = true or false }, null)%>
View 2 Replies
Similar Messages:
Apr 29, 2010
Lets say I have a simple controller for ASP.NET MVC I want to test. I want to test that a controller action (Foo, in this case) simply returns a link to another action (Bar, in this case).How would you test TestController.Foo? (either the first or second link)
My implementation has the same link twice. One passes the url throw ViewData[]. This seems more testable to me, as I can check the ViewData collection returned from Foo(). Even this way though, I don't know how to validate the url itself without making dependencies on routing.The controller:
public class TestController : Controller
{
public ActionResult Foo()[code].....
View 1 Replies
Sep 8, 2010
[Code]....
Somebody will come to my page, RenderMyThing.aspx ... and I always want to pass a list of strings
[Code]....
View 2 Replies
Mar 30, 2010
I am rather new to ASP.NET MVC and am trying to develop good practices and have studied a few tutorials and videos. There seems to be some differences in how people define the signature of a typical edit action method - sometimes the id (primary key) is listed and sometimes not. It seems like letting the framework do the model binding is a GOOD THING, so I will probably have the model (or view model) as a parameter:
ActionResult Edit(int id,
CompanyViewModel company);
ActionResult Edit(CompanyViewModel company);
But, should the id be a parameter too? I assume it is common-place to have the id in a hidden form field as well so the id (primary key) is then already bound in the model (or view model) - if so, what is the id parameter good for? Or should it be the other way around - keep the id parameter and do not bother using a hidden field for it? What are the pros and cons and what is the best practice?
View 6 Replies
Sep 8, 2010
public ActionResult RenderMyThing(IList<String> strings)
{
return View("RenderMyView");
}
How do I pass in strings?
routes.MapRoute("MyRoute", "RenderMyThing.aspx", new { controller = "My", action = "RenderMyThing" });
Is there a way I could pass in strings here?
Secondly, how does ASP.NET MVC know that action is my action, and controller is my controller. Like I saw this in samples, and it does work, but isn't it just an anonymous object with no type?
View 1 Replies
May 23, 2010
I'm sure something like this worked before for taking a type and pass it to another action method (I cannot / never use TempData)
[Code
View 6 Replies
Jan 22, 2011
@Html.ActionLink("Add a bill", "Create", new { controller = "Bill"}); This is the code I used to add an link to Create method in Bill controller. But in the view I saw Add a bill (/Bill/Create): So, how can I remove the brackets? (/Bill/Create). And, I also want this link to act as a button instead of a , how can I do that?
View 1 Replies
Dec 21, 2010
I know I can use Html.ActionLink(...) from my view to render an anchor tag with a link to an action. I know I can call RedirectToAction(...) from the controller to immediately call another action. But what I'd like to do (and don't know how), is get an action link from within the controller. I am building up a breadcrumb and want the link to an action. So I don't want to immediately jump to the action (as with RedirectToAction), but just get what the link would be.
View 3 Replies
Oct 6, 2010
I have code like this. Always the "Get" method is getting called insted of "Post" method eventhough I have explicitly mentioned it as "Post"
<%= Ajax.ActionLink("Create",
"Create",
new
AjaxOptions {HttpMethod =
"POST" })%>
View 2 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 3, 2011
In one view (view1) there is a text box and a button beside it. i click on that button, i am popping another view (Create view) as a seperate window. in create view i am entering some values and creating a record in db. out of these values one value i have to send back to "View1". how can i send this value? i am opening view2 from view1 like
<input type="button" value="Get ID"
onclick="window.open('<%=Url.Action("Create","Controller1") %>',
'','scrollbars=yes,width=800,height=800,resizable=yes');"
/>
View2 contains some fields like Name,Email etc... and I click "Create" to call HTTPPOST. there i add the values to db including a generated guid. i want to send this ID to view1.
View 2 Replies
May 27, 2010
i am currently working on an asp.net mvc 2 web app and would like to add some ajax functionality on my delete item actions.Show, on the list items displayed view page, i wrapped the list items inside a partial view and added an ajax delete action link for each item (inside a foreach loop):
[Code]....
On the AjaxDeleteItem ajax controller action, i delete the selected item and redisplay the updated items list (via UpdateTargetId = "divList", where the list items partial view resides).My question is how i could insert Antiforgery token in such a scenario in order to secure delete operations from CSRF and XSRF attacks.
View 1 Replies
Oct 26, 2010
When i click on a link, i want to do something with the variabels.
Pad = "C\Uploads\";
"j" is the name of the user.
Label1.Text = "<td><a runat='server' " + Test(Pad + x[j].ToString()) + "</a></td>";
When i click on this link i want to count how many people visited that link(store that count number in my database).
View 7 Replies
Mar 26, 2010
We have an ASP.Net page that uses a checkbox to toggle between a list view and a tree view. The problem is that this triggers a post. When we then click on one of the documents in the list, then press back in the browser, we get a page expired error. Is it possible to change the action of the check box to trigger a get with a parameter?
View 1 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
Dec 1, 2010
I have 2 classes that are used to mirror the data from an ajax call. One (Customer) contains a property which is name, and the other is an array of Products.
Public Class Customer
Private _Name as String
Private _Products as Product()
Public Property Name() As String
[Code].....
View 1 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
Sep 2, 2010
I have navigation and many link on my webproject from html action links. They are ugly with underline. I would like to insert some image with name or play with styles of action link.Is it possible? How to do that?
View 3 Replies
Aug 10, 2010
I am currently trying to make an html submit occur, but using the MVC helper method ActionLink as I do not want it to be a button, I want it to be an underlined link like the rest on my page. This is what I have currently
[Code]....
This jumps back to my action fine, but all the domains that are checked off to be deleted are not sent back. (if I use this,
[Code]....
it works fine so I know it's not something wrong with submitting or retrieving the check boxes)
View 4 Replies
Feb 11, 2010
How does one create custom (non-add, edit delete) buttons to a GridView control? Also how does one add space between the buttons?
View 8 Replies
Feb 8, 2010
I have one problem with actionlink. My Example is: i have one view(xyz.aspx) and controller(abc.vb) , in this view i put below line
<%=Html.ActionLink("Manage", "Index", "Advertisement", New With {.aintCampaignid = Cam.CampaignID})%>
I have another view(Index.aspx) and controller(Advertisement.vb) if click on manage link in XYZ view it will call to advertisement controller and index function But iam getting [URL] it wont call.
View 5 Replies
Feb 13, 2010
Ive been moving my site using forms over to MVC and have 2 html.action links in the default.master to MVC pages in the in the home folder that work just fine but when i add another mvc page in the home folder named links.aspx the application cant find the page from the html actionlink
[Code]....
there are no differences i can see in the pages that do show up and the one that cant be found (links.aspx).
there is no difference in the way ive written the link in the master.
I need about 6 or 7 of these links on the master to pages in the home folder.
View 3 Replies
Mar 4, 2011
I have an ASP.NET MVC controller action with the following VB.NET signature:
<HttpPost()>
Public Function ClosestCities
(ByVal position As MapCoordinate, ByVal citiesCount As UInteger) As JsonResult
The MapCordinate class is:
Public Class MapCoordinate
Public Latitude As Double
Public Longitude As Double
End Class
If I'm trying to send an Ajax POST in jQuery to the ClosestCities action, what should my request look like?
When I use the following code to POST to this action, in the debugger window of VS, position.longitiude and position.latitude are equal to 0.0 (0D):
[code]....
View 2 Replies
Apr 7, 2010
I've got menu in my ASP MVC project, and can when I use
<li><%= Html.ActionLink("My", "My")%></li>
it redirects me to .../Home/My
and if I got
<li><%= Html.ActionLink("My", "My", "ZZZ")%></li>
it redirects me to .../ZZZ/My
the problem is I've got some pages out of MVC , with simple Inherits and they are in the root so I need to got to /My.aspx
How can I redirect to /My.aspx in my MVC menu ?
View 1 Replies
Jan 12, 2011
I am using asp.net mvc 3 and I want to trigger the GridView action and pass the dropdownlist selected value in the action parameter.
@Html.ActionLink("View", "GridAction", new { action = $("#DropDownList1").val() });
View 1 Replies