Passing Value From Action Method To View From Where It Is Called
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
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.
Error:An item with the same key has already been added.
[ArgumentException: An item with the same key has already been added.] System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52 System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +9382923
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?
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.
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.
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.
i just want to be able to call a javascritp subroutine on the client, after the server has done its thing (when an action completes or control goes to the view, i'd dont mind calling the js from the view either).
for some reason, even vs2010 doesn't let me put breakpoints in <% ... %> tagged areas between <script...> and </script> tagged areas. i for this reason can't figure out whats going on and how it's running things. here is what i've put in my view, and the javascritp should run, but it doesn't....
im just trying to call "RunOnceRoutines;" but it's not getting called!
the 2 questions: how on earth do we call javascript methods from server, and where is all this lovely javascript debugging i've heard about since vs2008? no where to be found!
for debugging purposes, how do I see the ModelState errors from code in the action method? ModelState.IsValid returns false. I want to copy the error messages to a variable so I can display them in the debugger.
I am having a dropdown server control on view, when the user clicks the submit btn at that time the form gets posted. and a action method in view controller is called with verb=post.
But the problem is that how should i get reference to the dropdown server control in the action method of view controller?
I am creating an Asp.net web site which will support dynamic data. When I am creating a dynamic web site from Scratch (from template in VS) all is working fine. But when I am trying to add dynamic entity (.edmx) file and running the application I am getting following error
"The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. "
I am desiging a master and details page from a search page..user can search for something and I need to display the result in jqgrid if the result has more than 1 row or record.. if the result is just one record then i have to directly send then to details page by skiping grid page... I do have an action method for results page and one more action method for Jqgrid data..i am trying to check the row count for the database result and trying to redirect to details action results..but its not working at all..and showing an empty jqgrid..
The page I'm editing had three tabs, each tab contains a diffrent grid view which is populated by a search box with in the tab. Each row in the grid view has a check box. When a print button is pressed all records with a tick in the check box should be printed off. Then page then reloads but some of the content is missing due to the way the page has been coded. This is becuase some of the code is only called when the tab is clicked not on postback. Is there anyway that I change the following code so that it's called after postback? These are the functions that are causing the most problem.. I need them to be loaded for the correct tab on postback.. I can't do it for all three as the code takes forever to run in that case.
I have a simple ASP.NET web application for data collecting (a webform with two text fields and a Telerik editor, a button for submit with server side OnClick event listener attached).The event listener saves data on DB and then redirects to another page.Under development web server the application works fine.When published under IIS7 the event listener doesn't fire. The only way i found to make it work is to specify the action on the form tag:
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:
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?
I am having a problem with getting a listbox to update after the add method is called. I am using an AsyncFileUpload control and as part of the AsyncFileUpload1_UploadedComplete I am creating a listItem and then adding that to the listbox. The item will not appear in the listbox. I have tried putting the listbox in an update panel and then calling the Update method on the panel from within the AsyncFileUpload1_UploadedComplete procedure and that too fails to update the listbox. I can call the Update method on the panel from a separate procedure and still the listbox will not update with the item added in the AsyncFileUpload1_UploadedComplete method.
I would like to create one view for my CRUD actions. The view contains 3 basic DIV updatetargets ("search form", "search result listing" and "action" (would be create,detail,edit,delete). Basic flow would be: "Search" updates the "Search Result Listing", click on CRUD actions in listing would show partial view in "action".
how do I call to refresh the "Listing" after I do any add/update/delete without having user click search again?
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)%>
I can't understand why the method LoadViewState() is not called after the postback in my code below.After label1 cahnges its text the "__VIEWSTATE" hidden field is modified, but LoadViewState() is not called.