Read Model Values And Send Them By Ajax Post?

Feb 17, 2011

I have the following code and it`s pointing out errors as follows

Error 1 The name 'date' does not exist in the current context
Error 2 The name 'person' does not exist in the current context

What is wrong?

$("#test").Click(function () {
var date = $("#DateFrom").val();
var person = Model.SelectedPerson;
$.ajax({
url: '@Url.Action("testEmp","Employee",new {dateFrom = date, selectedPerson= person})',
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "html",
success: function (result) {
$('#text).html(result);
},
});
return false;
});

View 1 Replies


Similar Messages:

Read A Complex View Model On POST?

Jun 5, 2010

I have an user view model that has the following properties:

public User user;
public List<Language> Languages;

I send the above model to the view and use html helpers to build the form, so I end up with something like:

<form action="/Users/Edit/5" method="post"><input id="user_UserId" name="user.UserId" type="hidden" value="5" />
First Name
Last Name
Email
Language

Now, I try to read the POST in something that initially was something like :

[AcceptVerbs( HttpVerbs.Post )]

public ActionResult Edit( int UserId, FormCollection form ) {

and cannot get the user.UserId variable, user.FirstName variable etc.

what needs to be done to be able to read this kind of POST request. I'm kind of reluctant to modifying my ViewModel as it is very simple and easy to maintain as it is.

View 2 Replies

MVC2 Model Binding Does Not POST Back Hidden Values?

Jul 25, 2010

I have a /Register [GET] Action in the controller that pre-poluates a view-model with a string and an integer and returns: return View(myModel);I can see the string being populated in the textarea and the id being populated in a hidden input. Yet when the form gets POSTed, the string value is null and the int value is 0. I verified that both values are posted to the server but the model received in the POST action is missing those values.

View 1 Replies

C# - POST Json Without Model And Ajax?

Nov 23, 2010

For now, I just want to use HTTP POST to send json to asp.net mvc2 controller.Since the JSON is actually a list of JSON objects, and each of them has different fields & length, so it hard for me to make up a input model.So I want to know is there a way for me to post JSON without model/ajax to a controller in ASP.NET MVC2?

View 2 Replies

AJAX :: Programming Model - Getting Values Of Dropdownlists

Feb 6, 2010

Imagine I'm developing a webform with two dropdownlists and a submit button. The second dropdownlist depends on the choice in the first, and both are loaded dynamically using webmethods being called with javascript in de ASPX page (ajax). When I submit the form to the server, to save the data, I can't get the value of those dropdownlists. I think it is because with client AJAX no viewstate data is being generated. I need to send the data to the server and save the webform data, and identify wich data is on each webcontrol.

View 3 Replies

AJAX :: Passing Values From Model Pop Up To Text Box?

Nov 30, 2010

Am using a Model popup to show a grid view. From where the selected record should be posted back to a Text Box in the parent page. i loaded the grid succesfully i can post the values inside the modelpopup. but can't post the value to the text box in the parent page. and i use only server side code not client side scripting.

View 2 Replies

C# - Passing An Array Of Values In A JQuery Ajax Post?

Oct 13, 2010

I have a ListBox on my page, and I'd like to make an AJAX post containing all the selected items. Here's my code:

[code]...

I'd like to pass in the selected values either as an array, or a comma-delimited string. What's the best way to pass that data, and how can I do it?

View 3 Replies

JQuery :: Read Ajax Values In Aspx.cs Page

Nov 8, 2010

I'm how do I read the posted data. e.g. startRow in the aspx code behind page. Here is the ajax

$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default2.aspx/GetPageLinks",
data: "{isbn: '" + startRow + "'}",
dataType: "json",
success: function(msg) {
DisplayReviews(msg.d);
}

View 2 Replies

MVC :: Model State Doesn't Contain Model Values

Aug 2, 2010

when I use Html.HiddenFor( model => model.OwnerId ) to create a hidden field, the value assigned to that field is zero. When I use <input type="hidden" value="<%: Model.OwnerId %>" /> to add the hidden field to the form, the value is assigned correctly.

Why would Html.HiddenFor( model => model.OwnerId ) not get the correct value from the Model object? Am I supposed to load model state somehow separate from returning the model object from the action method? Here is the view:

[Code]....

The Create action method is relatively straight forward.

public ActionResult Create( ... )
{
ViewStockItem item = new ViewStockItem();
item.ActionCode = ActionCode.Add;
if (item.OwnerId == 0)
item.OwnerId = 7;
BookOwner owner = db.BookOwners.Single(c => c.OwnerId == item.OwnerId);
item.OwnerName = owner.OwnerName;
return View(item);
}

View 4 Replies

MVC :: How To Post A List Model

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

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

ASP.NET MVC 2 - POST Form Model From PartialView?

Mar 1, 2010

I have a single model type to wrap up various models I want to use in my view:

public class QuestionViewData {
public Question Question { get; set; }
public IList<Answer> Answers { get; set; }
}

Now, in my question view I pull the data from the Question object - that's fine. Secondly I iterate through all Answer objects and pass them to a partial view:

<% foreach(Answer item in Model.Answers) { %>
<% Html.RenderPartial("ShowAnswer", item); %>
<% } %>

For each answer (in the partial view) I have some action buttons (like ratings). I'm using separate form POST's with hidden fields for every button. The problem is that I can't post the whole QuestionViewData model to my action method cause I only have the Answer object as model in the partial view. However, I need to return the complete question view from that action that takes QuestionViewData as model.

View 2 Replies

C# - MVC - Using Model Property As Form - Post To Action?

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

C# - Get List<Model> Object In HTTP POST?

Dec 29, 2010

I have two model classes:

public class UserModel
{
public Guid Id { get; set; }
public string EmailAddress { get; set; }
public string LoginName { get; set; }
public string Password { get; set; }
}
public class GroupModel
{
public Guid Id { get; set; }
public string Name { get; set; }
public List<UserModel> Users { get; set; }
}

I created a View (Create.Aspx) by inheriting GroupModel class.

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MyApp.Models.GroupModel>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Create</title>
</head>
<body>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.Id) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Id) %>
<%: Html.ValidationMessageFor(model => model.Id) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Name) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Name) %>
<%: Html.ValidationMessageFor(model => model.Name) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</body>
</html>

It is generating only two fields (Id, Name) in my aspx view. Also I am able to get the form data in the Model class object in ё[HttpPost]ё request which contains the data for ID and NAME field in controller.

[HttpPost]
public ActionResult Create(GroupModel groupModel)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}

How can I get the data in List<UserModel> object? I am thinking to Put a List control with checkboxes containing Users. Then catch them using FormCollection object in controller.

View 1 Replies

C# - How To Fetch Return Values Between Jquery Functions And Post Ajax Jquery Request To Webservice

Aug 26, 2010

I have the following code where the function codeaddress geocodes the text feild value and returns geocoded value , geocoded value is stored in variable example ,how will i return the variable v2 to the function call and post to asmx webservice.

[code]....

View 1 Replies

How To Bind Post Data With A Model That Contains Multiple Models

Nov 4, 2010

I have a parent View that uses a few partial views. Each partial view has its own custom model. The parent View is a model containing each of the partial view's model. In other words this parent View model is NOT flat.

How do i get POST data to bind with the parent's model object? Do i have to write a custom model binder?

Update I'm not binding to a collection of objects of the same type (ie: a collection of uploaded files). I'm binding to object that contains multiple of objects. For example:

[code]....

View 1 Replies

MVC :: Retain Partial Data In Model Over The Post Backs?

Oct 12, 2010

I have recently started learning ASP.NET with MVC 2 Framework, I am facing difficulties in the following scenarios.In my MVC application I want to retain partial information in Model over post backs.Following is my scenario,

1. I initiate "Edit" of main record by clicking date hyperlink from left navigation.

2. Amend some data.

3. Save the record.

4. "Edit" sub record of the saved record by clicking another hyperlink from bottom left navigation panel.

The page is divided in to 6 tabs, the first 5 tabs shows the data for the main record and the 6th tab shows data of sub record. Wehn we "Edit@ sub record the previous 5 tabs doesn't have any changes noted, that means there is no harm in keeping their details intact in the main model. So is there a way to access model in the controller on hyper link click action so that I can only load the data for the clicked sub record (I am asking this, because the hyperlink click uses HTTP GET method so no model parameter passed in action method). If no, then how do I retain partial values in the Model over post backs?

Note that each tab data have been kept in individual models, and a main model has a collection member to hold all these individual models together.I thought as the model is binded with the view, it is too binded with controller. But it is allowing easily to access model in variable "Model" for the view but not for the controller.

View 3 Replies

Binding View Model From A Form Post With Inner Complex Types?

Apr 15, 2010

[Code]....

What I want to achieve is the ID of the property: item.Item.ID to be bound to the ID from the (route)URL. However I can't get it to work. I tried using [Bind()] attribute.

I fixed it now using a hidden field in the form like so:

<%= Html.HiddenFor(model => model.Item.ID)%>

However this feels a bit icky. I'd like to know if there is a better cleaner way of doing this?

View 1 Replies

MVC :: Saving A Complex Child Object After Post (LINQ To SQL Model Binding With MVC)

Jan 6, 2011

I am using ASP.Net MVC2 and LINQ to SQL. I am using DataAnnotations and model binding in conjunction with a Form/View and its working beautifully well. Loving that.. My view is an "Add new Employee" form that's adding a new "Employee" complex object. Every Employee also has a child complex object called an "Address".
I am using the bound Html helpers in the view, such as Html.TextBoxFor(model => model.NewEmployee.FirstName) for example. Working beautifully well, validating beautifully well both client and server and coming into the controller fully populated and ready to be saved! Exciting.. ModelState.IsValid returns true and I go to save the new Employee.

The Employee is created fine but the system also creates a blank/new Address record in my Addresses table even when the Address fields are blank! How can I prevent any Address from being created, in situations where I ONLY want to create a new Employee with no Address. An example is when the user supplies an existing Address, then I wish to simply set the new Employee's AddressID to that of an existing physical address (I hope that makes sense). But it could apply to any situation where you need to create a new complex object, but you don't wish for LINQ to create any of its child complex objects. I have tried setting NewEmployee.Address = null after it is received in the controller, but even after that, a blank/new Address is still created. Even if I try NewEmployee.Address = SomeExistingAddress, it does correctly link the Employee to the existing Address, but it STILL goes off and creates another redundant new/blank address record! Which is really weird..

View 10 Replies

MVC + LINQ To SQL Model Binding - Saving A Complex Child Object After Post

Jan 5, 2011

I have a "Create New Employee" ASP.Net MVC form. My complex object is an Employee and an Employee has an Address, which is another Complex object. On my View/Form I collect all required values for both the Employee and the Address. I'm using the bound HTML helpers such as: Html.TextBoxFor(model => model.EmployeeAddress.StreetName)

AND

Html.TextBoxFor(model => model.NewEmployee.FirstName)

This is all working beautifully well. Model binding is working like a dream, both server side and client side validation using DataAnnotations is working beautifully well and I am nicely receiving my populated complex objects as expected in the Controller.. Now I'm trying to save.. The Employee should always be newly created, because its an "Add New Employee" form. But sometimes the Address is an existing Address and I don't want to insert another one. Rather, I just want to link the Employee to the existing AddressID of the one that already exists in the database.

So I wrote a nifty GetExistingOrCreateNewAddress(Address PostedAddress) method which works great so I end up with the correct Address to use and link to the about to be saved Employee object. This is all happening in the same DataContext, so no problems there..

BUT even when I link the about to be saved Employee object to an existing Address, on save a new/empty Address row is created in my Addresses table. Even though the newly created Employee does link correctly to the existing Address I told it to! Why is it so??? And how can I save the new Employee without LINQ automatically creating a blank Address for me. Because I'm explicitly specifying an existing Address it should be linked to instead!

[HttpPost]
public ActionResult CreateEmployee(EmployeeDetailsViewModel NewEmployeeDetails)
{
if (ModelState.IsValid)
{
EmployeeRepository ER = new EmployeeeRepository();
// Fetch or Create the appropriate Address object for what has been entered
Address ActualAddress = ER.GetExistingOrCreateNewAddress(NewEmployeeDetails.EnteredAddress);
// Link this Address to the "about to be saved" Employee
NewEmployeeDetails.Employee.Address = ActualAddress;
// Lock it in..
ER.SaveNewEmployee(NewEmployeeDetails.Employee);

View 2 Replies

Read A HTTP Post Request With Some Data

Nov 9, 2010

I am using an Zencoder API to transcode video files. Once the job is completed they will do a HTTP POST with XML or JSON data containing the Job ID and other info to the url we provide.

So if URL is www.abc.com/GetZencoderResponse.aspx or .ashx, how can I read the data they post?

excuse me for the underlines, i thought that would make my query stand out.

View 6 Replies

C# - Use WebRequest To POST Some Data And Read Response?

May 18, 2010

Need to have the server make a POST to an API, how do I add POST values to a WebRequest object and how do I send it and get the response (it will be a string) out?I need to POST TWO values, and sometimes more, I see in these examples where it says string postData = "a string to post"; but how do I let the thing I am POSTing to know that there is multiple form values?

View 2 Replies

Service To Read Emails And Post To A Webform Or Database?

Jun 8, 2010

I guess it doesn't matter what technology I use, but I'm wanting to send an email to a specified email address then have some service either POST to a webpage or Insert into an open SQL database.

View 5 Replies

C# - MVC View Model Text Data Lost After The Post - Display Them In The Case Of Failed Validation?

Nov 12, 2010

I've got a view model that has some text properties. And I use Html.DisplayFor to display them on the screen. But those text data won't be post back, so in the case of failed validation, the returned view won't have those data. How do I handle this kind of situation?

View 2 Replies

Send A Plaintext Raw Http Post Request?

Jan 29, 2010

All I need is to send a http post request I pulled from fiddler.

I do not want to use HttpWebRequest class. It makes it hard to set up a request, does not allow to change host,

and when it does send it it looks nothing like the request I want. The server is very sensitive and unless I copy the request headers 100% it will return an empty page. Why can't I just type in the headers and send it that way? What would be 5 minutes of
work in php is taking the whole evening in asp.net.

This is what I am trying to send, simple as it gets: ...

View 9 Replies







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