In MVC 4 kendo grid, I have passed like this in link column.
columns
.Bound(m => m.TID )
.ClientTemplate("<a href='"
+ Url.Action("AddMerchant", "Merchant", new { MerchantId = 10 ,AddressId = 30})
+ "'>Edit</a>");
so i got like this
/Merchant/AddMerchant?MerchantId=10&AddressId=30
But I need
/Merchant/AddMerchant/10/30 .
but if I get I can't able to read parameter value in action named like MerchantId and AddressId
You can achieve it by map custom routes to the RouteConfig.cs file for your controller and its action method:
routes.MapRoute(
name: "Merchant",
url: "Merchant/AddMerchant/{MerchantId}/{AddressId}",
defaults: new { controller = "Merchant", action = "AddMerchant }
);
Related
I am trying to use typeahed twitter for bootstrap
https://github.com/twitter/typeahead.js
I need to change the remote dynamically according to what user types in and ANOTHER parameter.
(The goal is to retrieve the cities of a country)
trying with country="en"; does not affect it
trying with autocompleter.remote=".."; does not work.
Any idea ?
<script>
var country="fr";
var autocompleter = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: 'ajax.php?action=getVilles&country='+country+'&ville=%QUERY'
});
autocompleter.initialize();
$('#city').typeahead(null, {
name: 'city',
displayKey: 'city',
source: autocompleter.ttAdapter()
});
</script>
This is what I've done:
var tagStudies = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "autocomplete/study",
replace: function(url, uriEncodedQuery) {
study = $('#study').val();
ssp = $("#social-security").val();
return url + '?q=' + uriEncodedQuery + '&s=' + study + '&ssp=' + ssp
},
filter: function (parsedResponse) {
return parsedResponse.studies;
}
}
});
Take a look at the replace function. The first parameter is the url, and the second is what the user is typing. I made a concatenation to pass the query and 2 extra params.
If you copy the code, make sure you replace 'text' for 'value' in datumTokenizer. Hope it helps
I have an ajaxfilter on a YII listview. When I select an item in the checkboxlist everything works properly: ajax calls vacature/index and gives 'vacature' the right ID which I handle in my controller, so this works fine. (vacature/index?vacature=13)
Now when I uncheck the same item it does exactly the same call, so it passes the id of the changed item. I only need it to not pass the id of the de-selected item and the string to be empty.
Thanks in advance!
echo CHtml::beginForm(CHtml::normalizeUrl(array('vacature/index')), 'get', array('id'=>'filter-vacature'))
echo CHtml::checkBoxList('niveau', (isset($_GET['niveau'])) ? $_GET['niveau'] : '',
CHtml::listData(Lov::model()->findAllByAttributes(array('wat'=>'opleiding')), 'id', 'item'),
array('class'=>'niveau','template'=>'<span class="checkbox-columns">{input} {label}</span>', 'separator'=>''))
$('.niveau').change(function(){
niveau = $('.niveau').serialize();
$.fn.yiiListView.update(
'ajaxListView',
{data: niveau}
);
});
I added a comparison to check if the string is empty, and pass the working empty value:
$('.niveau').change(function(){
niveau = $('.niveau').serialize();
if(empty(niveau))
{
niveau = 'niveau%5B%5D=0';
}
$.fn.yiiListView.update(
'ajaxListView',
{data: niveau}
);
});
Following is my Html.Actionlink
#Html.ActionLink("Change Team", "Edit", "UserPlayers", new { MatchId = ViewBag.MatchId, UserId = ViewBag.UserId })
When i run the application I get this
http://localhost:50013/UserPlayers/Edit?Length=11
as a link.
I dont know from where is the "Length=11" coming.
You need to add a null as the last parameter:
#Html.ActionLink("Change Team", "Edit", "UserPlayers", new { MatchId = ViewBag.MatchId, UserId = ViewBag.UserId }, null)
Without this, you are using the wrong method overload for Html.ActionLink()
i am having two routes
context.MapRoute("",
"Route1/{controller}/{programid}/{action}"
);
context.MapRoute("",
"Route2/{controller}/{programid}/{action}"
);
Url.Action("action2", "controller2", new{programid = 123});
Resultant URL : Route1/controller2/123/action2
Is it possible to get the url below:
Expected URL : Route2/controller2/123/action2
Modify your route as
context.MapRoute("Route1",
"Route1/{controller}/{programid}/{action}"
);
context.MapRoute("Route2",
"Route2/{controller}/{programid}/{action}"
);
Then use Url.RouteUrl like
Url.RouteUrl("Route1", YourRouteProperties }
or
Url.RouteUrl("Route1", new { controller = "YourController", action = "YourAction",
programid= "YourProgramId"}}
I have 2 stores. SortStore and WorkStore.
This is my WorkStore fields in the model:
{name: 'domainName',type:'string',mapping:'DomainName'},
{name: 'objectId',type:'string',mapping:'ObjectID'},
{name: 'serverName',type:'string',mapping:'ServerName'},
{name: 'sourceWorkset',type:'string',mapping:'SourceWorkset'},
{name: 'sourceWorkstep',type:'string',mapping:'SourceWorkstep'},
This is my SortStore fields in the model:
['name', 'value']
I want to display data from workstore in a list based on the items in the sortstore. if sort store has domain name and object id. The list should populate only those values from the workstore. Stores are getting dynamically loaded by webservice call.
{
xtype:'list',
id:'workitemlist',
// store:'WorkitemStore',
itemTpl:'<table><tr><td valign="top"><img src="{workitemImage}" width=20px height=22px />' +
' </td><td><span><b>{workitemName}</b></span> <br/>' +
'<span class="label">Object Id:</span> {objectId} <br /><span class="label">' +
'Source Workstep: </span>{sourceWorkstep}</td> </tr></table>'
}
Instead of printing all these in itemTpl I need only those present in sortstore to get populated. How to dynamically set this itemTpl based on the items in some other store. Any help is appreciated.
We can dynamically set itemTpl this way:
var template = '<table><tr><td valign="top"><img src="{Image}"' +
' width=20px height=22px />' +
' </td><td><span><b>{Name}</b></span> <br/>';
var myStore = Ext.getStore('RealStore');
if (myStore != null) {
myStore.each(function (record) {
if (record.get('field')) {
template += '<span class="label">Domain Name:</span>' +
' {field} <br/>';
}
}
Not sure if that's the best way but the way I have implemented it in past was to keep JSON of templateId(using differentiating field e.g. "tpl_"+field) & templateContent for my app and load it on startup in a variable(tpls). Once it is loaded I can refer it from anywhere like this:
var styleTemplate = eval('tpls.tpl_' + rec.field);
and then pass it to list like this:
{
xtype: 'list',
itemTpl : styleTemplate,
store : listStore,
id : 'ilid',
layout : 'fit'
}