Return value from a partial view loaded on a jquery dialog - asp.net-mvc-4

I have a partialview "selectUser". On this partial view a user can search for other users. The user id will be stored in a hidden field or as a var on my view. I need to use this partial view in many places. Lets say I need to return the id of the selected user on the close event of my dialog. My question is, how do I make this partial view, loaded as a modal dialog with jquery ui, to retrun the selected value to its parent view? Is there a way to access the value directly from the parent view?

I think I follow what you are needing now. So on your button click you do an ajax call back to the server and include the destination field name in the call
$.ajax({
url: "#(Url.Action("Action", "Controller"))",
type: "POST",
cache: false,
async: true,
data: { destination: 'fieldName' },
success: function (result) {
$(".Content").html(result);
AttachScript();
Dialog.load();
}
});
On your controller send that field to the partial view through your view model or viewbag and on the partial view put that field name in a hidden field. then in your button click you should be able to do something like this (untested)
function AttachScript(){
$('.btnSubmit').on('click', function(){
var data = $('.sharedField').val();
$($('.HiddenField').val()).val(data);
});
}
which will set the value of whatever field is named in your hidden field to the data. Hopefully this helps.

Related

how to give a onclick action in a EXTJS.?

I am new to Extjs,I create a grid panel in extjs, with toolbar. I give a add button, in controller the button name is given. in view, i create a tool bar in create function, not in define. Using alias i create one name also, by using that widget name i used to call in controller, by using button action value give thew function foropen a new, but it notworking. If i use panel within init function in view part means it will not disply any panels.
and my coding is
Ext.create('Ext.toolbar.Toolbar', {
alias : 'widget.toolbar',
renderTo: document.body,
items: [
{
itemId : 'addtab',
text: 'Add',
iconCls: 'add',
action: 'addtab'
}]
})
this is the view part. action here i given as addtab
and my controller is
init: function() {this.control({
'toolbar button[itemId=grid-add]': {
click: function(){
top.addTab(true,"../medias/add","Media","common",0,'add');
}
}
})
button is working.. and my add page is also working fine. but the calling function that is cal by alias is not working. can anyone give the solution.
i want to give the function in controller file only.
thank you..

using modal for each item in a list in yii framework

There is a list of patient data using a "TbGridView" widget,
Now, I want to use modal widget for each one of the patient here, so, that
the patient id is passed to the modal for each patient with patient id.
I had tried this, but, I am being unable to pass each patient id to the modal form.
Any response related to this would be very helpful.
Thank you.
Actually there is no direct way of doing that I mean that you cant render dynamic data by passing an id. Modal is static.
You can use ajax call for that to retrieve data from database and render that data in your modal. Follow these steps
1. In your gridview use rowHtmlOptionsExpression to set id for specific row.
2. create an action in your controller to handle ajax call.
3. use jquery click event on TbGridView elements like
$('#mygrid table tbody tr td:not(:first-child)').on('click', function() {
var Url =<?php echo '"' . CController::createUrl('/user/default/viewMessageAjax') . '"'; ?>;
var id = $(this).parent().attr('id');
console.log($(this));
$.ajax({
url: Url,
data: {id: id},
success: function(data) {
$('.modal-body').html(data);
$('#myModal').modal('show');
}
});
})
jQuery('#mygrid >table>tbody>tr:first-child').live('click', function() {
return false;
})
above code is just an example, you can change it according to ur needs.

Passing full data from a store in to a view

I currently have a list that is populated via a store which works fine. When you click on a list item, my controller gets the record of that list item and passes those details to the view that is pushed on to the stack.
Is there a way to push the full data store in to the view that is added so that it can be referenced? (e.g. I have a list of events, and on the page for a specific event I want to reference the store and bring back the time of the next upcoming event after it)
Here is my current function that pushed the individual record to the view:
showDetail: function(dataview, index, item, record){
this.getMain().push({
xtype: 'ScheduleDetails',
data: record.data
});
}
Any help would be great. Thanks.
I found the answer. You can use dataview to access the store itself and then either pass that to the view as an object or just create a variable (as I have in the example below) and pass it as a parameter of your push function.
showDetail: function(dataview, index, item, record){
//Next event is the item in the record that I wanted to use to reference another record
var nextevent = dataview.listItems[record.data.nextevent]._record._data;
this.getMain().push({
xtype: 'ScheduleDetails',
data: record.data,
nextevent: nextevent
});
}

Controller function not called after opening another tab in extjs mvc 4.0

I've a function in controller of extjs4.0 MVC it called on button
which is in view page but when I open another tab then this function not called
on button
Kindly help me in this matter
//------------- Code
init: function() {
var controller = this;
this.control({
'leftPanel button[action=reset]': {
click: this.resetForm
},'leftPanel button[action=search]' : {
click: this.searchForm
}
})
}
these 2 function will not call again if open another tab on my site
Kindly help me in this matter
Thanks
actually the fields are in view page like
this
buttons: [{
text: 'Reset Filter',
name :'btnReset',
id:'btnReset',
action:'reset'
},{
text: 'Perform Search',
name:'btnSearch',
id:'btnSearch',
action:'search'
}
]
you can see in config option defined
the name of the function 'search , rest' which is defined in controller of the page (as I posted on my question). this function works
properly when page load and if we not perform any action of this page where these function called but when I' opening a tab (by Using Ajax Request) after that the above function not called no error messages appear.
hopefully you can understand the problem

ExtJS4 trigger doLayout on store load

I have a grid with store: cdStore defined. The grid's records are edited using a form which is bound to the grid data. When updating a record, I would like for the refreshed records to show in the grid.
Currently I have
handler : function() {
areaForm.getForm().submit({
params: { action: "update" }
});
cdStore.loadPage(cdStore.currentPage);
areaGrid.doLayout();
}
It seems like this fails sometimes and older data remains displayed in the grid - perhaps doLayout() is called before the page is fully loaded.
Can I trigger a doLayout on loadPage somehow?
// ...
cdStore.load({
callback: function(){areaGrid.doLayout();},
page: cdStore.currentPage
});
Update
I would appreciate a line or two with an explanation if you would be so kind
You said that "doLayout() is called before the page is fully loaded" and you were right. So the doLayout must be called after the data is loaded. The one way to do that is to use load method. You can pass array of options into this method:
store.load({
page: 2,
limit: 50,
// and
callback: function(){ /*do something*/ }
});
The function you pass as callback is called exactly after the data is loaded. So doLayout() put into callback produces correct behaviour.