I am using Kendo UI with ASP.NET MVC. I am tying to use the Scheduler control. The Scheduler control is not posting the DataSourceRquest object back to the controller when I am writing
dataSouce.filter(criteria);
The criteria in this case is the filters populated using AND operator. The above line is not posting any filters back to the controller.
Also, even the scheduler's next date and previous date button are also not posting any date filters.
Is this expected behavior or am I missing something?
Conroller
public ActionResult GetList([DataSourceRequest] DataSourceRequest request)
{
return Json(_service.GetList(request), JsonRequestBehavior.AllowGet);
}
Javascript
dataSouce.filter(criteria); // Where dataSource is Kendo Scheduler dataSource
And criteria object in console looks like this --> Object{ logic: "and", filters: Array[1] }
But nothing is posted back to the MVC action method??
Related
I'm new to ASP.NET MVC 5(MVC and Web API in general), I'm looking for a good approach to creating my viewmodel in the MVC controller based on data I get back from making a Web API call.
The web api call method returns data like this
public ActionResult GetConfigTable([DataSourceRequest] DataSourceRequest request)
{
var emp = new fpECMEntities();
IQueryable<Models.MyTable> empSecurity = emp.MyTable;
DataSourceResult result = empSecurity.ToDataSourceResult(request);
return Json(result, JsonRequestBehavior.AllowGet);
}
my views controller method looks like this
public ActionResult Config_Read([DataSourceRequest] DataSourceRequest request)
{
var configTable = Json(MySolution.API.Controllers.HomeController.GetConfigTable());
// fill in the code
return Json(result, JsonRequestBehavior.AllowGet);
}
Where the API is a separate project within the solution which keeps all the Models and acts as a DAL. So, here I need to add additional columns to the JSON data I get back from API before I send it off to the Grid in the view.
My questions is
Is this the right approach to create the viewmodel in my MVC controller by massaging the data here
Is it better to create a method within the API that generates all the data required for my ViewModel?
If #1 is ok, then what is the code to massage the data? do I have to deserialize the JSON data into Dataset and then add columns and return it as JSON again?
Any and all advice is greatly appreciated. BTW, I'm using the Kendo UI grid at the client, the types DataSourceRequest and DataSourceResult are from Kendo.UI.DataSourceRequest library.
Thanks
i have a custom action filter in my mvc 3 web application that performs Logs on a database and i would like to get more information about the Action that is accessing the user so i have this code now:
[ActionFilters.ProductStream(Message = "PUBLISH a Product")]
public ActionResult PublishProducts(PublishedContainerVO publishedContainer) {
//some code
}
And i would like to do something like this:
[ActionFilters.ProductStream(Message = "PUBLISH a Product", Id = publishedContainer.Id)]
public ActionResult PublishProducts(PublishedContainerVO publishedContainer) {
//some code
}
Is that possible? I have seen that inside the Action filter i can access that parameters by his key, but in this case... i have a complex object and not a simple id.
You can't, because metadata are created at compile time.
I'm developing an MVC3 application with EF and I wanted to make the UI fluent using jQuery ajax, the user will be able to navigate through the url, if he knows it or maybe he might receive a link pointing to a particular route, but, once the page is fully loaded it needs to be fluent, so I came up with one idea and I would like to discuss it here before I make the changes to the solution.
Here is what I came up with:
TestController.cs (Methods code has been omitted for simplicity)
public ActionResult Index() { ... }
public ActionResult Create() { ... }
[HttpPost]
public ActionResult Create(Test test) { ... }
public ActionResult Update(int testID) { ... }
[HttpPost]
public ActionResult Update(Test test) { ... }
public ActionResult Delete(int testID) { ... }
[HttpPost]
public ActionResult Delete(Test test) { ... }
So far it looks like most controllers. My views are as follows:
Views\Test\List.cshtml
Views\Test\Create.cshtml
Views\Test\Details.cshtml
Views\Test\Delete.cshtml
Now since I wanted to do it async: I've changed my List view so I could add, modify and remove from the list, so far is working like a charm. Plus, the user could still be able to navigate through the application using the url's, note that every link inside the application will perform an ajax request to do the actual work, there are no Route/Action links.
By now the application is working as expected, but now I came across something: there are views that I need to be ActionResult and PartialViewResult, that is because the user could type in the url: "/Admin/Test", which should return the full page, or could click on an anchor which will load only the content of the "/Admin/Test" and display it. To avoid the famous page inside page errors I wrote a function to send the request, and when the request arrives it selects only what I need, avoiding then the page inside page, and to duplicate views, but, the response is the whole page which, I don't need to say, it's not the best option, but since the application will be used by lan I didn't care too much about the payload of the response, but then I needed to write javascript code inside the views, so my solution was like null because using the jQuery selector to get only what I need the javascript wasn't there.
As for my new solution to solve my last solution:
I thought I might leave the original view as is, and create another view appending the word "Partial" after the original name, creating another method in the controller with the same naming convention, plus adding the new Route to my Route Table.
To wrap things up, what I need is the following:
- If the user types in "/Test" the response should be the entire page, loaded like the old days, screens flashing white and such.
- But if the user clicks the Test link in the navigation bar, the response should be async and refreshing only the content of my layout.
Any ideas? thoughts? suggestions?
In your actionmethod you can have
if (Request.IsAjaxRequest())
return PartialView("_somePartialView");
else
return PartialView("_someOtherPartialView");
I'm looking to enable "saving" of form data prior to submission.
I want users to be able to save form progress, even when the form is in an invalid state, and then come back to it at a later time.
Now, my only problem is that I want to be able to use UpdateModel method to update my model. However, as the form is potentially invalid or just partially complete, this will throw an error.
Is there a way to annotate the following method such that validation is ignored in the SAVE instance?
[HttpPost]
public ActionResult Save(Model values)
{
var model = new Model();
UpdateModel(model);
}
I want to save having to write a 1-1 mapping for the elements being saved - which is my fallback option, but isn't very maintainable.
Give TryUpdateModel(model) a try, should fit your needs.
This won't throw an exception, and it will update the model and then return false if there are validation errors.
If you care about the errors, you check the ModelState in the false instance.
Hence, you can use it as so to always save changes:
[HttpPost]
public ActionResult Save(Model values)
{
var model = new Model();
TryUpdateModel(model);
model.saveChanges();
}
[Edit] To try to clarify:
I have a view that needs to be launched from an external application. The application requires string data to be passed from an external application (the data is free text and too long to pass as a query parameter), So I would like to launch the MVC application with a POST request. The view that is launched also needs to post data back to itself in order to submit the data it collects for storage in a database. So I end up with a View with two HttpPost flagged methods in my controller (MVC throws an error that there are ambiguous Create methods).
So in the code below Create() would be posted to from the external application. Create(FormCollection collection) would be posted to when a displayed View is submitted.
//POST: /Application/Create
[HttpPost]
public ActionResult Create()
{
MyModel model = new MyModel();
//Parse External Data to model from Request.InputStream
return View(Model);
}
//POST: /Application/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
//Save form collection data to database
return RedirectToAction("Index");
}
So long story short, how can I post data to an MVC application to launch a view, without getting an error for an ambiguous call.
Thanks.
in the first case when the post method comes in from the outside:
return View("ConfirmCreate", model)
Then create an action method named ConfirmCreate. After ConfirmCreate is called the second time you will redirect back to Index as you have.
So I was able to do this by changing the POST call to load the application to a PUT To avoid have duplicate post endpoints), then sending the PUT from an ajax call in another application and replacing the current document with the returned html from the successful ajax call. Thanks for the suggestions.