I have a Kendo Dropdownlist as follow,
Html.Kendo().DropDownList()
.Name("CountryName")
.HtmlAttributes(new { style = "font-size:8pt;width:110px" })
.DataValueField("Id")
.DataTextField("Description")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("CountryAjax", "Shared");
});
})
Where
[HttpPost]
public ActionResult CountryAjax(string countryId)
{
var countries = this._decodeBL.GetAllCountriesList();
return new JsonResult
{
Data = new SelectList(countries, "Id", "Description", "Canada")
};
}
But the dropdownlist is empty. When set break point in CountryAjax, it doesn't stop there (means that CountryAjax is never executed). BTW, this code works fine for Telerik ASP.Net MVC. What is the problem? Thanks.
You are not supplying a countryId parameter. If the method signature was public ActionResult CountryAjax() it will fire I think.
Related
i have two method httpget as
public ActionResult MiReport()
{
return View();
}
and httppost as
public ActionResult GetReportView(string startdate,string enddate) {
ReportModel Obj = new ReportModel( startdate, enddate );
return PartialView("GetReportView",Obj );
}
I am binding grid as
#using GridMvc.Html
<div class="col-md-12">
<h4><strong>REPORT</strong></h4>
#Html.Grid(Model.lstReport).Columns(columns => {
columns.Add(c => c.rep).Titled("REP");
columns.Add(c => c.businessName).Titled("BUSINESS NAME");
columns.Add(c => c.contactNmae).Titled("CONTACT NAME");
}).WithPaging(10)
</div>
I am showing it on View its loading the first 10 row fine but when i am clicking on paging button its calling the Get method and page is getting reloded.
Please help me.
Thanks in Advance.
You need to have your grid be given a name like this (Index.cshtml):
.WithPaging(10, 10, "grid1")
Now in the Index method change it to :
public ActionResult Index(String grid1 = "")
Now when you click on the page, you will see page number in the url as grid1=3,this will be read into parameter grid1 of Index method.
Now in this method check:-
if (!String.IsNullOrEmpty(grid1))
{
//my grid was populated based on PersonnelId selected in some dropdown on the view.You can use the variable in which you stored your key.
id = TempData["TimeOffPersonnelID"].ToString();
}
Hope this helps!!
Trying to work with the Telerik Kendo UI MVC AutoComplete control. I'm using server side filtering which works. The results are coming back in the controller method, but I'm seeing 'Undefined' in the list of choice on the view. The MVC details are below.
View
#model List<USFS.Lending.LoanApprovalConditionSetup>
#(Html.Kendo().AutoComplete()
.Name("Conditions")
.DataTextField("ConditionName")
.BindTo(Model)
.MinLength(3)
.Filter(FilterType.Contains)
.Placeholder("Conditions Search...")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("SearchLoanConditions", "LoanCondition")
.Data("onConditionsSearch");
})
.ServerFiltering(true);
})
)
<script>
function onConditionsSearch() {
return {
searchText: $("#Conditions").val()
};
}
</script>
Controller
public ActionResult SearchLoanConditions(string searchText)
{
if (string.IsNullOrEmpty(searchText))
{
searchText = String.Empty;
}
IEnumerable<LoanApprovalConditionSetup> loanConditions = SearchConditions(searchText);
return PartialView("_searchConditions", loanConditions.ToList());
}
Model
My model is a standard class with properties in it.
Any help would be great!
Thanks
Jim
I have the following scenario, using mvc3:
I have a database table which holds a RecordID, RecordName and RecordType. Displayed are three text boxes, one for each of the fields mentioned previously.
My Question is, when i enter a RecordID into the relevant text box, i want to be able to show the RecordName and RecordType for that particular RecordID. How can i achieve this?
In View:
#Html.TextBoxFor(model => model.RecordId)
#Html.TextBoxFor(model => model.RecordName)
#Html.TextBoxFor(model => model.RecordType)
<script language="javascript">
$('#RecordId').change(function(){
var recordId = this.value;
$.getJSON("/MyController/GetRecordById",
{
id: recordId
},
function (data) {
$('RecordName').val(data.Name);
$('RecordType').val(data.Type);
});
});
</script>
In Controller:
public JsonResult GetRecordById(int id)
{
var record = recordRepository.GetById(id);
var result = new {
Name = record.Name,
Type = record.Type
}
return Json(result, JsonRequestBehavior.AllowGet);
}
I have a view with several controls that are used for searching. When a user searches (Ajax.BeginForm) off of these I return the data into a PartialView (Telerik MVC3 Grid) that was generated dynamically.
This all works fine. In the grid are buttons for selecting a row. When I select a row, it posts to my controller, I do some "stuff" etc. When I try to get back to the view all I get is my grid data on a page by itself, it displays like a table with no borders, no other controls etc. My code is below.
My partial grid:
#model Highlander.Areas.Highlander.Models.ViewModels.DeliveriesGridViewModel
#using System.Data;
#(Html.Telerik().Grid<System.Data.DataRow>(Model.Data.Rows.Cast<System.Data.DataRow>())
.Name("Grid")
.DataKeys(dataKeys => dataKeys.Add("DeliveryID"))
.Columns(columns =>
{
columns.Command(commandbutton =>
{
commandbutton.Select().ButtonType(GridButtonType.ImageAndText);
}).Width(80).Title(ViewBag.Title);
columns.LoadSettings(Model.Columns as IEnumerable<GridColumnSettings>);
})
.DataBinding(dataBinding => dataBinding.Server().Select("_MarkSystem", "Deliveries"))
.EnableCustomBinding(true)
.Resizable(resize => resize.Columns(true))
)
My Controller:
[GridAction]
public ActionResult _MarkSystem(GridCommand command, int id)
{
string shipDeliver = DataCache.ShipDeliver;
DataTable fullTable = DataCache.FullTable;
// call to function to get the datatable data based on the id
rHelpers.GetDataTableRow(id, fullTable, shipDeliver);
// get the data for the grid into the model
fullTable = DataCache.FullTable;
model = new DeliveriesGridViewModel();
model.Data = fullTable;
model.Columns = rHelpers.NewColumns(DataCache.FullTable);
return PartialView("_DeliveryGrid", model);
//if (Request.IsAjaxRequest())
//{
// return PartialView("_DeliveryGrid", model);
//}
//return PartialView("_DeliveryGrid", model);
//return PartialView("DeliveryManager", model);
}
As you can see I have tried various things with no success.
Can anyone give me some direction on this.
Thanks for your time.
As far i understand you are using dataBinding.Server() that call a server side binding. Use .Editable(editing => editing.Mode(GridEditMode.InLine) it will work.
Both kind of bindings (Server and Ajax) needs a editing mode. Put an editing mode and try again.Kindly Response if it does not work for you. Here full code of data binding:
**.DataBinding(dataBinding => dataBinding.Ajax()
.Select("myAction", "myController")
.Update("myAction",myController")).
Editable(editing => editing.Mode(GridEditMode.InLine))**
I have 2 dropdownlists on the Index page, and I wish to pass the id's of the selected items to the Create Page, so that I can populate the 2 dropdownlists on the Create page the same as the Index page.
Can you please suggest how I can do this?
At the moment I have this in the Index View :-
#Html.ActionLink("Create New", "Create", new { LeagueId = "ddlLeagues" }, new { ClubId = "ddlClubs" })
And then in the Controller :-
public ActionResult Create(int LeagueId, int ClubId)
{
var _LeagueID = LeagueId;
var _ClubID = ClubId;
Any help is very much appreciated!
Thanks
You can do it as described in this post:
ActionLink routeValue from a TextBox
you basically need to wrap your dropdowns with a form that routes to the create function, and the submit will take care of passing those values to your controller because they will be in the form data:
#using(Html.BeginForm("Create", "Footballer", FormMethod.Get))
{
#Html.DropDownList("LeagueId", Model.Leagues)
#Html.DropDownList("ClubId", Model.Clubs)
<input type="submit" value="Create"/>
}
If you are using a strongly typed model that has Properties for LeagueId and ClubId then use:
#Html.DropDownListFor(m => m.LeagueId, Model.Leagues)
#Html.DropDownListFor(m => m.ClubId, Model.Clubs)
Model.Clubs and Model.League are the IEnumerables that you will use to populate your dropDowns ofcourse
in your controller make sure you have the following:
[HttpGet]
public ActionMethod Create(int LeagueId, int ClubId)
{
//return your Create View
}
[HttpPost]
public ActionMethod Create(FormCollection data)
{
//Perform the create here
}
You can add a route into the application RegisterRoutes :
routes.MapRoute(
"CreateFootBallerWith2ComboOptions",
"{controller}/{action}/{LeagueId}/{ClubId}",
new { controller = "Footballer", action = "Create", LeagueId = -1, ClubId = -1 } // Default Values
);
You can then use what Bassam suggest with the ActionLink which is a Html Helper.
#Html.ActionLink("Create New", "Create",
new { LeagueId = 1, ClubId = 213 });
or use directly from the browser using :
localhost:7246/Footballer/Create/1/5