MVC :: Post Action Model Parameter
Jan 26, 2011
i wonder something about mvc post method. for example I created a view "strongly typed" from a model (MyModel).
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Demo1.Models.MyModel>" %>
for Create actionsthere is two way.
first one takes MyModel as parameter
[HttpPost]
public ActionResult cart(MyModel md, int someID)
{
//some code
//.....
return View(MyModel);
}
second one does not take parameter as model.
[HttpPost]
public ActionResult cart(int someID)
{
//some code
//.....
return View(Mymodel);
}
for first one way, after form post the form values does not delete, I mean form does not cleared,after second one form is be cleared. why this diffirence?
View 5 Replies
Similar Messages:
Jan 12, 2011
public class BandProfileModel
{
public BandModel Band { get; set; }
public IEnumerable<Relationship> Requests { get; set; }
}
and the following form:
<% using (Html.BeginForm()) { %>
<%: Html.EditorFor(m => m.Band) %>
<input type="submit" value="Save Band" />
<% } %>
which posts to the following action:
public ActionResult EditPost(BandProfileModel m, string band)
{
// stuff is done here, but m is null?
return View(m);
}
Basically, I only have one property on my model that is used in the form. The other property in BandProfleModel is just used in the UI for other data. I'm trying to update just the Band property, but for each post, the argument "m" is always null (specifically, the .Band property is null). It's posting just fine to the action, so it isn't a problem with my route. Just the data is null.
The ID and name attributes of the fields are BAND_whatever and Band.whatever (whatever being a property of Band), so it seems like it would work. What am I doing wrong? How can I use just one property as part of a form, post back, and have values populated via the model binder for my BandProfileModel property in the action?
View 2 Replies
Jun 12, 2010
My httppost action doesnt seem to have received my model. The code is below;
[Code]....
i put a breakpoint on the line; return RedirectToAction("Error", "Dashboard"); and i found that appQualif carried no values whatsoever from the form i submitted..
View 5 Replies
May 20, 2010
I'm trying to add file upload functionality to a page. I've got a form that posts the selected file to a controller with a 'savefile' method. But if I don't add a get version of 'savefile' I'll get a 404 error. Here is the form code which is presented on the Index page:
[Code]....
And here is the controller code:
[Code]....
Intuitively I don't think I should need a GET version of SaveFile but if omit it I get a 404 error when the form posts. Why should I need a GET version of SaveFile when all I want is to post a form and save the file?
View 4 Replies
Feb 24, 2011
My problem with the following is how do I send the ModelStateErrors to the action Employee, when I go through the catch part in DeleteEmployee
[Code].....
With return View("Employee", model); I a still not able to send the ID and Name as parameter.
View 5 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
Jun 4, 2010
I'm trying to implement paging in my app, so i need to know what page the user wants to click on, as well as pass the model (for some fields)I'm able to pass the desired page, just not the model (for the search criteria)here is my view:
[Code]....
Heres my Controller Action
[Code]....
My ViewModel SearchResults has a string property "Search". When i do it this way searchModel == null in the NextPage Action.
View 2 Replies
Apr 22, 2010
I have need to provide a URL to a controller and action in one of my model classes. Is this possible to do with out providing the entire webaddress as well?
View 10 Replies
Jan 23, 2011
@using (Html.BeginForm("Index", "Bill"))
{
@Html.Label("FromDate")
@Html.DropDownList("FromDate",Model.DateList)
@Html.Label("ToDate")
@Html.DropDownList("ToDate", Model.DateList)
@Html.ActionLink("Filter", "Index", "Bill") // I want to post to Index
}
[HttpPost]
public ActionResult Index(string fromDate, string toDate)
{
//Process
}
What is the correct way to post the date range to Index action?
What kind of URL do I need to specify?
View 1 Replies
Mar 31, 2011
Why is a null parameter being passed to the following controller action?
public FileContentResult GetImageForArticle(ArticleSummary article)
{
if (article == null || !article.ContainsValidThumbNail()) return null;
return File(article.ThumbNail, article.ThumbNaiType);
}
from the following partial view:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<AkwiMemorial.Models.ArticleSummary>>" %>
<%if (Model.Count() > 0) [code]...
View 1 Replies
Nov 25, 2010
I've an action method like the below:
[HTTPPost]
public void Edit(Movie movie)
{
}
Movie has fields Id, Name. View is displaying name only in textbox. When button is clicked, the above action method's movie is populates with the updated name value but Id is 0, actually that record's id is 4. Thatswhy my updating of record is not working. Why MVC is putting 0 into id?
View 9 Replies
Sep 16, 2010
I am using ASP.NET MVC 1. I want to pass an int value to from an action to view. I can use 2 ways.
Use ViewData dictionary.
Define a class to contain the int value.
Other these two, Is there a way to pass the int value to view so that I can get the int value using just Model like
<label><%= Model %></label>
View 2 Replies
Oct 19, 2010
I'm trying to use the jQuery.post() function to post an object to an action method, but for some reason the nested objects aren't initialised properly when they're received by the action method.
Here's my javascript code:
[Code]....
And my action method:
[Code]....
company.Id has a value of 10, but company.User.Id is 0. what I'm doing wrong? I've not named any properties incorrectly, by the way.
View 1 Replies
Mar 2, 2010
I must miss something obvious here when using htmlbegin form. I noticed that it takes (or tries to take me) right to the view rather than the an action. If I replace SearchAction with SearchResult is goes nicely to the view, not considering the action.
Using SeachAction leads to the error that it cant find the view.
View 12 Replies
Mar 28, 2011
I have an ActionResult that accepts POST, however is there a work around for me to redirect from a controller to another controller containing this POST method/action?
View 3 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
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
May 13, 2010
i am thinking to capture which button has caused a postback in the web pages.
Is it possible to do so?
View 2 Replies
Nov 7, 2010
I saw a post with posibble problems with Model Binding which is mentioned here. [URL]. Whats the best approach to this? Different approaches are below.
[Code]....
View 2 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
Jan 18, 2011
Customer(Id,Name),
Phone(Id,CustomerId,Number)
Contact(Id,CustomerId,Name,Address)
In My Form
Customer Name : <Textbox>
Phone : <TextBox> <button> : button to Add More <Textbox> Phone to add multiple Phone
Contact Name : <TextBox>
Address : <TextBox> <button> : button to Add More Form Contact add multiple Contact
View 6 Replies
Jul 4, 2010
i am making a forum application using MVC 2. I have a ForumController which has Index and Create Actions. The Get Create Action returns View and the Post Create Action takes an argument of type "ForumEntry". When i generate create view i make sure that i check "create strongly typed view" and i select models.ForumEntry Model and NOT the models.Forum Model. The Forum model is ADO.NET enitity model that maps to Forum Table. I want to catch ForumEntry type into my Create Post action but mysteriously i get a Forum Object. I have verified this by returning Content When :
[HttpPost]
Public ActionResult Create(ForumEntry entryToCreate)
{
return Content (entryToCreate.Title); // No Output
}
When
[HttpPost]
Public ActionResult Create(Forum entryToCreate)
{
return Content (entryToCreate.Title); // output == new entry that i typed in the create form
}
I am baffled as the create Form is of type FormEntry. Here is the code for create View
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Aspforum.Models.ForumEntry>" %>
View 5 Replies
Jul 12, 2010
I am having a problem where when I form post to an action it gets null values in my hosted enviroment although if I use a model to bind to it works fine. Everything posts and works correctly when I run the project.
So far I have tried to pass the form fields back as parameters on the action and get the value through the context request. Both work fine but as soon as I publish it to the hosted enviroment, it doesn't work. in the view I have:
<%=Html.TextBox("subject") %>
<%=Html.TextBox("comment") %>
for the action Method:
[HttpPost]
[Authorize]
public ActionResult Reply(int? id, string subject, string comment)
{
//Some code...
}
I have verified that it is hitting the action but the subject and comment values are null. I am guessing I am missing something simple, maybe a security setting in the config, that is causing this since I am still fairly new with MVC. I am running VS 2008 with MVC2.
View 4 Replies
May 12, 2010
ia ma working on an asp.net mvc 2 app and i have a Users view, displaying all the users of the database. Then, i would like to add the ablility to display "users starting with fisrt name" capabaility on the same view. For this i created a list of all english leters that actually are links (<a href="#">A</a>, etc...)
I managed to handle the click event of each one of the letters and get the corresponding letter via jquery, but i don't know how to call theHttp.Post Users/FindUserByFirstLetterName(string letter) on the click event.
I cannot use the Html.ActionLink<> helper, since it redirects me to the HttpGet controller action.
I also tried using using jqery.Post but i also couldn't manage to call the action.
View 7 Replies
Apr 1, 2010
I am working with MVC2 and one of the view model's properties is IDictionary<Int32, String>.
This is not to be changed on the view. But when the form is posted back I would like to still get those values.
Can Html.Hidden store this property values?
How should I do this so the model still gets the IDictionary<Int32, String> values on the POST action?
View 2 Replies