MVC :: Passing Of Id To Edit Action

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


Similar Messages:

MVC :: Edit Action (GET And POST) For An Entity That Multiple Pages Link Into (GET EDIT)?

Jan 5, 2010

Consider the following scenario.You have a Edit action (GET and POST) for an entity that multiple pages link into (GET EDIT). What is the best way of getting back to the page that linked to the edit action? Adding a returnTo url in the query?

Example, from MyCart/3 we have a edit product link
/Product/Edit/5?returnTo=MyCart/3 (but url encoded)
And from Producer/45 we have this link
/Product/Edit/5?returnTo=Producer/45

Is there a better way to do this?

View 4 Replies

How To Tell Create Button To Send To An Action Named Create And To Edit To An Action

Mar 14, 2010

I'm a newbie into MVC and I am like only on chapter 7 in ASP.NET MVC Unleashed so be easy with m

[Code]....

how do I tell Create Button to send to an Action named Create and to Edit to an Action named Edit on the same form?I guess it is possible on ASP.NET MVC if it is possible on ASP.NET Webforms

View 6 Replies

MVC :: Passing List To Action

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

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

Passing A Parameter To Action Method?

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

MVC :: Passing Model From One Action Method To Another

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

MVC :: Edit Action Not Updating?

May 21, 2010

I have an edit action that is not updating. The code is below. When i debug the code , i see my udated field but it doesnt seem to get saved into the database.

[Code]....

View 2 Replies

Javascript - Passing JSON To Controller Action

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

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

<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

Passing Form Data To Mvc Controller Action Using JQuery?

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

Passing Complex JSON Data JQuery To Action?

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

MVC :: Passing Json Collection Object From View To Action

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

MVC :: Edit The Content Of A View From An Action Filter?

Jan 6, 2011

Is it possible to edit the content of a view from a action filter.

What I am working on is a Resourcemanager that I can use to manage

my style sheets, js and other resources. I want to be able to put

lines in the the view any where like Html.ResourceManager.AddScriptFile("MyScript")

or Html.ResourceManager.AddCSSFile("MyCSS")

and at the end of the view call Html.Render(); this would then place the content of my resources at this point. My problem is that I want to put the CSS stuff at the top of the view, but them problem is that it is renderend at the end of the view, so I tought that I could use a ActionFilter to move it to the top of the view.

1) What would be the best way to do this task ?

2) Is there any resources that describe the way that the MVC framework works in more detail ?

View 2 Replies

JQuery Ajax With MVC Action - Passing Arguments From JavaScript In POST

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

MVC :: Deal With Dictionay Of View Model When Edit Action

Jun 3, 2010

I have a dictionary in my user's view model used to store user's roles:

[Code]....

In my edit view:

[Code]....

the code above generates:

[Code]....

It seems that when I edited the checkboxes' value and post to server, the UserEditViewModel.Roles is empty.

View 2 Replies

Include AJAX Code So That On Pressing DELETE Or EDIT Gives Pop-up Box, Confirming Action?

Jun 10, 2010

I have a GridView with EDIT, DELETE AND SELECT options.Now I want to include AJAX code so that on pressing DELETE or EDIT it gives me a pop-up box, confirming my action.

View 8 Replies

MVC :: Passing 3 Objects In Edit Form?

Apr 1, 2011

I have an Edit form that utilizes the following ViewModel:

[Code]....

SUserDetail, User and CUDetail are LINQtoSQL classes in my [ .dbml ]. What the above ViewModel allows me to do, is provide a nice and neat Edit form populated with data from the above 3 objects.

However I am stuck on how to handle the HTTP Post for the Edit Action.

View 5 Replies

Forms Data Controls :: Dynamically - Programmatically Set Action(Edit - Delete) Button For A ListView Item

Feb 11, 2011

I've a listview in which i'm binding data from objectdata source. I have a requirement where i've to allow edit/delete for only certail listviewitem which meets specific requirement. How do i dynamically set that some item can be only be edited not deleted thus only edit button/link should appear and vice-versa.

View 2 Replies

Web Forms :: Passing Multiple Command Arguments In GridView Edit Button

Apr 25, 2012

I am having a grid with the three column date, and mode.The last column is Edit.

When i click the edit button, i need to get the corresponding date and mode and show in the pop up. for that it is possible to pass two value in the command ergument.?

View 1 Replies

MVC :: Pass Item_Id Parameter Into "Edit Action" To Update?

Mar 28, 2011

I have code Controller :

[Code]....

I use Viewer :

[Code]....

how i can pass Item_Id parameter into "Edit Action" to update?

View 4 Replies

Forms Data Controls :: Passing Parameters To Stored Procedure When Edit Button Is Clicked In GridView

Oct 27, 2010

I have a grid view that populates and displays data at btn click event from the following sql statement in one of the SP:

SELECT

reg_code, pc_serial, act_code
FROM user_reg
WHERE reg_code=@reg_code

I want to pass parameters to the other Stored procedure when the edit button is clicked in order to update the 2 columns in the specific row at the time. I now how to pass parameters in a regular btn click event or function, but in the case of edit btn in grid view I don't know how to capture data from specific row and then pass it to the SP. Here is Stored Procedure to update the columns (every user always has the same reg code, but may have more than one serial number and activation code, I want to let the user update serial number and then based on the serial number generate new activation code in the SP.):

[Code]....

View 3 Replies

MVC :: Why Synchronous Action Wasn't Executed Until Asynchronous Action Completed

Nov 29, 2010

I'm implement Comet in Asp.net MVC, I used timer to keep Async request in server, Async request will complete when timer elapsed 1 minute and response to client (to avoid 404 error) and then reconnect to Async Controller. I also wanna execute some Synchronous action during Async request was holding, but the problem is: When an Async action was executed and hold by using timer, the Sync Action wasn't called until Async action (comet long-live request) completed. I did test with firefox 3.6 many times, but the result is the same, so strange, Do you know why ? I have a sub some questions : To implement comet, using timer (response after some minutes elapsed) or thread (response after several time sleeping thread) to hold async request, which is better?

View 1 Replies

MVC :: Redirect Action Not Working In Jqgrid Action Results Method

Mar 23, 2011

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..

[Code]....

View 9 Replies

Test That A Controller Action Simply Returns A Link To Another Action?

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







Copyrights 2005-15 www.BigResource.com, All rights reserved