Bootstrap 4 datetimepicker inside table incorrect design - html-table

I have a problem with Bootstrap 4 by displaying calendar on input field that is inside a table - the whole design is looking weird and doesn't display correctly. If the input field is outside the table, the design is good.
How it should look:
CSS file is included in BundleConfig.cs
EDIT: This is the CSS styling for tables:
.table thead:not(.domispicker) {
background: linear-gradient(to bottom, #187D99 0%,#145F75 1%,#145F75 26%,#187D99 100%);
color: white;
}
.table tbody tr:not(.domispicker), .table tbody tr:not(.domispicker) input, .table tbody tr:not(.domispicker) select, .table tbody tr:not(.domispicker) textarea {
background: linear-gradient(to bottom, #f2f2f2 0%,#feffe8 100%) !important;
}
th:not(.domispicker), td:not(.domispicker) {
vertical-align: middle !important;
}
I'm using 'domispicker' in class for input element but the style is still overriden.
The table html looks like this:
<tbody data-bind="foreach: documentData">
<tr data-bind="click :$parent.documentDataSelectRow.bind($data,$index()),
css: { 'row-selected': $parent.documentDataSelectedRowPosition() != null && $index() == $parent.documentDataSelectedRowPosition() && ForDelete() == false, 'for-delete': ForDelete() == true }">
<td class="checkbox-column"><span class="fa fa-upload" style="color:darkgreen" data-bind="visible: Id() == 0"></span></td>
<td>
<input type="text" class="form-control input-sm" data-bind="value: Description, attr : {'disabled' : (ForDelete() == true|| OnlyRead() == true) }, event:{ change: $parent.documentDataModified}">
</td>
<td data-bind="text: Id() != 0 ? TypeName : '#SharedResources.Index.MedicalDocument', attr : {'disabled' : ForDelete }"></td>
<td style="position: relative">
<input id="Doc`enter code here`umentDate" type="text" class="form-control search-input searching-date-from-to picker domispicker" data-bind="datePicker: DocumentDate, maxDate: new Date(), valueUpdate: 'afterkeydown',
attr : {'disabled' : (ForDelete() == true || OnlyRead() == true) }, event:{ click: $parent.documentDataModified}" placeholder="#SharedResources.Index.Date" />
</td>
<td id="btnDownload" class="action-column">
<a style="text-decoration:none;" class="fa fa-download download-nohover" title="#SharedResources.Index.Download" data-bind="attr: { href: DownloadLink },visible: Id() != 0 && ForDelete() == false, click: function(){window.location.href=DownloadLink();}"></a>
</td>
<td class="action-column">
<div class="row-delete fa fa-share icon-flip" title="#SharedResources.Index.Undo" style="color: #096224; cursor: pointer;" data-bind="click: $parent.documentDataUndoRemove, visible: ForDelete() == true"></div>
<div class="row-delete fa fa-minus-circle" title="#SharedResources.Index.Delete" style="color: #9E0101;cursor: pointer;" data-bind="click: $parent.documentDataRemove, visible: ForDelete() == false, css: { 'icon-disabled': OnlyRead() }"></div>
</td>
</tr>
</tbody>

Add custom class to your main table and style only direct children of that table using child combinator (also remove your current CSS code). This will prevent from styling tables which are used inside picker.
HTML:
<table class="table my-table...
CSS:
.my-table > thead {
background: linear-gradient(to bottom, #187d99 0%, #145f75 1%, #145f75 26%, #187d99 100%);
color: white;
}
.my-table > tbody > tr,
.my-table > tbody > tr input,
.my-table > tbody > tr select,
.my-table > tbody > tr textarea {
background: linear-gradient(to bottom, #f2f2f2 0%, #feffe8 100%) !important;
}
.my-table > thead > th,
.my-table > thead > td,
.my-table > tbody > th,
.my-table > tbody > td {
vertical-align: middle !important;
}

Related

Check box selection issue in vue.js

Please look the below image
I have two users and their allowed channels.
My issue is :
When I click one channel of a user, the same channel is also get checked of other user. For example:
When I click Commissions of user Deepu, the channel Commissions of user Midhun also get checked.
I have to avoid that, the clicked channel of the user should only selected, not other user's.
I tried this
<v-data-table
:headers="headers"
:items="UserChannels"
:loading="datatableloading"
class="elevation-1"
>
<template v-slot:items="props">
<td class="text-xs-left">{{ props.item.username }}</td>
<td class="text-xs-left">
<ul class="channel-listitems">
<li v-for="item in Channels">
<input type="checkbox" class="channel-checkbox" :value="item.id" v-model="checkedChannels">
{{ item.channel_name }}
</li>
</ul>
<br>
<span>Checked names: {{ checkedChannels }}</span>
</td>
</template>
</v-data-table>
I am using Vue.js for doing this.
You can create mapping dict for each user Channels selection.
Please refer following codepen - https://codepen.io/Pratik__007/pen/oNgaXeJ?editors=1010
In data
checkedChannels:{},
Created
created () {
console.log(this.Channels)
let vm = this;
this.Users.map(function(item){
vm.$set(vm.checkedChannels,item['name'],[])
return item;
})
},
The official Vue docs states, you can use v-model on multiple checkboxes using the same array. ( Docs : https://v2.vuejs.org/v2/guide/forms.html#Checkbox )
Also working example : https://codesandbox.io/s/hungry-kepler-t7mkw
Select elements for array with checkboxes and v-model
<template>
<div id="app">
<!-- First, iterate over all users -->
<div v-for="(user, index) in users" class="user">
<p class="name">{{ user.username }} - Checked Channels {{user.channels}}</p>
<!-- Create checkbox for each available channel, and v-model it to user.channels -->
<div class="channel">
<label v-for="(channel, index) in availableChannels">
{{channel}}
<input type="checkbox" v-bind:value="channel" v-model="user.channels">
</label>
</div>
</div>
</div>
</template>
<script>
export default {
name: "App",
data() {
return {
users: [
{
username: "User1",
channels: ["channel1", "channel2"]
},
{
username: "User2",
channels: ["channel3"]
}
],
availableChannels: [
"channel1",
"channel2",
"channel3",
"channel4",
"channel5"
]
};
}
};
</script>
<style>
.user {
min-height: 100px;
display: flex;
align-items: center;
border: 1px solid black;
margin-bottom: 10px;
justify-items: center;
}
.name,
.channel {
flex: 1;
}
.channel {
min-height: 100px;
display: flex;
flex-direction: column;
}
</style>

Two sortable items dragged if trying to move just one card from the sortable group

I have implemented sortablejs in Polymer2.0 element. I am able to drag and drop the item from group. The issue I am facing now is that randomly, not sure why and how, but 2 cards or items gets moved in a group list. Here's the screenshots.
todos is an object which contains group of lists which have array of items.
List
https://www.dropbox.com/s/9wp6vv668p3ckr2/Screenshot%202019-04-30%2007.18.16.png?dl=0
End state when dropped (you see 2 cards moved to the new column which I don't want. I only wanted one card to move)
https://www.dropbox.com/s/int4uyyl3945tjv/Screenshot%202019-04-30%2007.18.50.png?dl=0
Code: Polymer element html
<div class="board­__sprint">
<template is="dom-repeat" items="{{todos}}" as="row" restamp>
<div class="list">
<div class="list­-content">
<div style="float: left; width: 100%; text-align: center;">
<div style="float: left; width: 80%; text-align: left; padding-top: 10px;">
<h7 style="color: black; font-size: 20px; font-weight: 800; padding-left: 10px;margin-top: 5px;">
[[row.tasks.length]]
</h7>
<h7 style="color: black; font-size: 12px; font-weight: 200; padding: 2px; margin-top: 5px;">
[[row.title]]
</h7>
</div>
<div style="float: left; width: 20%; text-align: center;">
<paper-icon-button icon="icons:delete-sweep" style="color: grey;" id="deleteNote" row="[[row]]"
on-tap="_removeColumnTriggerDialog"></paper-icon-button>
</div>
</div>
<div style="display: table;">
<div style="width: 90%; height: 3px; background: #0c66b5;">
<h7> </h7>
</div>
<div id="myid[[row.id]]" class="list-group" style="min-height: 120px;">
<template is="dom-repeat" items="{{row.tasks}}" as="todo" restamp>
<!-- <div class$="{{determineDragable(todo)}}"> -->
<div class="item">
<div class="ticket" data-index$="{{todo.id}}">
<paper-card style="float:center; width: 100%;" class="singleColor" data-index$="{{todo}}"
data-index$="{{row}}">
<div style="float:left; width: 15%" style$="{{getRandomInt(0, 20)}}">
<h7> </h7>
</div>
<div style="width: 100%">
<div style="float: left; width: 15%; vertical-align:center">
<px-icon icon="px-vis:pin"></px-icon>
</div>
<div style="float: left; width: 70%">
<h7 class="banksTitle" style="color: black; font-size: 12px; text-align:left;">
<b>[{{index}}]</b> [[todo.actTitle]]
</h7>
<h7 class="banksTitle" style="color: grey; font-size: 12px; text-align:left;">
[[todo.actDesc]]
</h7>
</div>
<template is="dom-if" if="{{checkDummy(todo)}}">
<div style="float: left; width: 15%;">
<paper-icon-button icon="icons:close" style="color: grey;" id$="bt_readmore"
todo="[[todo]]" row="[[row]]" on-tap="_moveDel"></paper-icon-button>
</div>
</template>
<template is="dom-if" if="{{checkDummyNot(todo)}}">
<div style="float: left; width: 15%;">
<paper-icon-button icon="image:crop-square" style="color: grey;" id$="bt_readmore"
todo="[[todo]]" row="[[row]]" on-tap=""></paper-icon-button>
</div>
</template>
</div>
<div>
<h5> </h5>
</div>
<div style="width: 100%;display: table;">
<div style="float: left; width: 15%;">
</div>
<div style="float: left; width: 70%; text-align: center;">
<template is="dom-if" if="{{checkDummy(todo)}}">
<paper-icon-button icon="av:playlist-add-check" style="color: green;"
id$="bt_readmore" todo="[[todo]]" row="[[row]]" on-tap=""></paper-icon-button>
</template>
<template is="dom-if" if="{{checkDummy(todo)}}">
<paper-icon-button icon="editor:attach-file" style="color: maroon;" id$="bt_readmore"
todo="[[todo]]" row="[[row]]" on-tap=""></paper-icon-button>
</template>
<template is="dom-if" if="{{checkDummy(todo)}}">
<paper-icon-button icon="editor:border-color" style="color: grey;" id$="bt_readmore"
todo="[[todo]]" row="[[row]]" on-tap=""></paper-icon-button>
</template>
</div>
<div style="float: right; width: 15%;">
</div>
</div>
</paper-card>
</div>
</div>
</template>
</div>
</div>
<div>
<h5> </h5>
</div>
<div class="addTicket">
<paper-button raised class="blue" on-tap="_addTicketDialog" row={{row}}>Add Ticket</paper-button>
</div>
</div>
</div>
</template>
</div>
and the JS script specific to onAdd event of sortablejs
_todosChanged() {
setTimeout(() => {
console.log('this.todos.length = ' + this.todos.length);
var self = this;
if (this.todos !== null || this.todos !== undefined) {
var lowestOrder = 0;
var highestOrder = 0;
var options = {
group: 'shared',
animation: 200,
sort: false,
draggable: ".item",
onAdd: function (evt) {
console.log('---FROM----');
console.log(evt.from.id);
console.log('---TO----');
console.log(evt.to.id);
console.log('---ITEM----');
console.log(evt.item.innerText);
var foundFrom = false;
var fromId = evt.from.id.substr('myid'.length);
var fromCol;
var foundTo = false;
var toId = evt.to.id.substr('myid'.length);
var toCol;
console.log('fromId =' + fromId + ' toId =' + toId);
self.todos.forEach(child => { //todos = 1, 3, 4 & row = 3
if (!foundTo) {
if (child.id === toId) {
foundTo = true;
toCol = child;
}
}
if (!foundFrom) {
if (child.id === fromId) {
foundFrom = true;
fromCol = child;
}
}
});
console.log('toCol = ' + JSON.stringify(toCol));
console.log('fromCol = ' + JSON.stringify(fromCol));
//find item in from col
var str = evt.item.innerText;
var itemKey = str.substr(0, str.indexOf(':'));
itemKey = itemKey.substr(itemKey.indexOf('KEY-')).substr('KEY-'.length);
console.log('itemKey = ' + itemKey);
var arrItemToRemove = fromCol.tasks;
console.log('arrItemToRemove = ' + JSON.stringify(arrItemToRemove));
var indexItem = -1;
for (var i = 0; i < arrItemToRemove.length; i++)
if (arrItemToRemove[i].id === itemKey) indexItem = i;
console.log('indexItem = ' + indexItem);
if (indexItem < 0 || indexItem > arrItemToRemove.length) {
document.getElementById('toastError').show('No item found');
} else {
// console.log('indexItem=' + indexItem);
var newItemToPush = arrItemToRemove[indexItem];
console.log('newItemToPush=' + JSON.stringify(newItemToPush));
//now add the item to the right
var arr = toCol.tasks;
if (arr === null || arr === undefined) arr = [];
arr.push({
'actTitle': newItemToPush.actTitle,
'actDesc': newItemToPush.actDesc,
'actDt': newItemToPush.actDt,
'parent': toCol.order,
'id': newItemToPush.id
});
console.log('arr=' + JSON.stringify(arr));
self.$.query.ref.child(toCol.$key).child('tasks').set(arr);
var nwArr = arrItemToRemove.splice(indexItem, 1);
document.getElementById('toastShort').show('Data moved: ' + newItemToPush.actTitle);
self.$.query.ref.child(fromCol.$key).child('tasks').set(arrItemToRemove);
}
},
};
this.todos.forEach(child => {
if (lowestOrder > child.order) lowestOrder = child.order;
if (highestOrder < child.order) highestOrder = child.order;
// console.log(child.id);
var selector = this.shadowRoot.querySelector('#myid' + child.id);
Sortable.create(selector, options);
});
console.log('lowestOrder=' + lowestOrder + ' highestOrder=' + highestOrder);
this.set('order', highestOrder);
}
});
}
Ok ... this is what I did to resolve the issue
firebase query is async so I used observer function to update the dummy variable which is used in dom-template. I used async to do that.
The real issue was when you remove element from list that sortablejs has used to render the items. By use of Dummy variable that is copy of firebase object I was able to avoid this issue.
I offline sync the object when user leaves the page. It works fine now.

Hide bootstrap row column based on the data

I am running one jquery kendo grid row template where i am showing some content with images.Below is the code :
<table id="grid" style="width:100%">
<colgroup>
<col class="photo" />
<col class="details" />
<col />
</colgroup>
<thead style="display:none">
<tr>
<th>
Details
</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3"></td>
</tr>
</tbody>
</table>
<script id="rowTemplate" type="text/x-kendo-tmpl">
<tr>
<td style="width:30%">
div class="row">
<div id="dvImage" class="col-sm-4" style="width:118px">
#= imagelink #
</div>
<div class="col-sm-8" style="width:400px">
<span class="name" style="font-size:14px; color:green">#: Link #</span>
</div>
</div>
</td>
</tr>
</script>
<style>
.name {
display: block;
font-size: 1.3em;
}
.k-grid-header .k-header {
padding: 0px 20px;
}
.k-grid-content {
overflow-y: auto;
}
.k-grid tr td {
background: white !important;
border: 0 !important;
border-color: transparent;
}
.k pager-wrap {
border-width: 1px !important;
border-color: #ccc;
}
.k-block, .k-widget, .k-input, .k-textbox, .k-group, .k-content, .k-header, .k-filter-row > th, .k-editable-area, .k-separator, .k-colorpicker .k-i-arrow-s, .k-textbox > input, .k-autocomplete, .k-dropdown-wrap, .k-toolbar, .k-group-footer td, .k-grid-footer, .k-footer-template td, .k-state-default, .k-state-default .k-select, .k-state-disabled, .k-grid-header, .k-grid-header-wrap, .k-grid-header-locked, .k-grid-footer-locked, .k-grid-content-locked, .k-grid td, .k-grid td.k-state-selected, .k-grid-footer-wrap, .k-pager-wrap, .k-pager-wrap .k-link, .k-pager-refresh, .k-grouping-header, .k-grouping-header .k-group-indicator, .k-panelbar > .k-item > .k-link, .k-panel > .k-item > .k-link, .k-panelbar .k-panel, .k-panelbar .k-content, .k-treemap-tile, .k-calendar th, .k-slider-track, .k-splitbar, .k-dropzone-active, .k-tiles, .k-toolbar, .k-tooltip, .k-button-group .k-tool, .k-upload-files {
border-color: transparent;
}
.col-md-2 {
width:118px
}
.col-md-3 {
width:25%
}
</style>
In the above code i have Image and description which i am showing but for some of the rows i don't have image but still it's containing the space. So here i need that if image is null for particular row then it should hide that image column. I tried like this but did not get any luck.
Below is the code:
$("#grid").kendoGrid({
autoBind: false,
dataSource: {
transport: {
read: {
url: "/Home/GetSearchData",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { searchTerm: $('[id*=hdnHomeSearch]').val() }
},
parameterMap: function (data, operation) {
return kendo.stringify(data);
}
},
pageSize: 10,
schema: {
parse: function (data) {
debugger;
var items = [];
var chkCorrectVal = 0;
var context = $('#dvImage');
for (var i = 0; i < data.data.length; i++) {
if (data.data[i].CorrectValue != null && data.data[i].SearchValue != null) {
$("#spnSR")[i].innerHTML = "<b>" + "Get results for this text: " + "</b>" + data.data[i].CorrectValue;
$("#spnSV")[i].innerHTML = "<b>" + "Searched for this text: " + "</b>" + data.data[i].SearchValue;
chkCorrectVal = 1;
}
else {
if (chkCorrectVal == 0) {
$("#spnSR").hide();
$("#spnSV").hide();
}
}
if (!data.data[i].imagelink) {
var getContext = $(context[i]);
data.data[i].imagelink = "";
$(context[i]).addClass('hidden');
}
}
var product = {
data: data.data,
total: data.total
};
items.push(product);
return (items[0].data);
},
}
},
dataBound: function () {
DisplayNoResultFound($("#grid"));
},
serverPaging: true,
pageable: {
refresh: true,
pageSizes: true
},
rowTemplate: kendo.template($("#rowTemplate").html()),
});
});
One more example i am pasting here where i am trying to get the same results and that is working fine for me.
Below is the code:
<input type="submit" id="soltitle" value="#1"/>
<div class="row">
<div class="col-md-2" id="hell1">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"></h4>
</div>
<div id="timeline1" class="panel-collapse collapse">
<div class="panel-body">
<a href="#" class="thumbnail">
<img class="img-responsive" src="http://placehold.it/250x160" alt="Thumb11" />
</a>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"></h4>
</div>
<div id="timeline1" class="panel-collapse collapse">
<div class="panel-body">
<a href="#" class="thumbnail">
<img class="img-responsive" src="http://placehold.it/250x160" alt="Thumb11" />
</a>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#soltitle').click(function () {
$('#hell1')
// Find parent with the class that starts with "col-md"
// Change class to "col-md-3"
.closest('[class^="col-md"]')
.toggleClass('col-md-2 col-md-2 hidden')
// Find siblings of parent with similar class criteria
// - if all siblings are the same, you can use ".siblings()"
// Change class to "col-md-2"
//.siblings('[class^="col-md"]')
// .removeClass('col-md-3')
// .addClass('col-md-2');
});
});
</script>
in this example i am hiding first column in button click event and that is working fine.
The problem is that you toggle the class for all rows where the image does not exist. Each time you toggle those and toggle again, the second toggle negates the first one. If the rows where the if is evaluated to true is pair, then the last toggle was a negation.
It is not clear whether you need to hide the whole column if you find one such row, or you need to hide the column only for the affected row specifically. Also, your if is incorrect.
If you want to hide the whole column if at least such a row exists, then this might be the solution:
var shouldShow = true;
for (var i = 0; shouldShow && (i < data.data.length); i++) {
if (!data.data[i].imagelink) {
$(".imageClass").addClass('hidden');
shouldShow = false;
}
}
If you want to do it only for the affected row, then something like this might help you:
var context = $(".imageClass");
for (var i = 0; i < data.data.length; i++) {
if (!data.data[i].imagelink) {
$(context[i]).addClass('hidden');
}
}
The code assumes you have a single column having imageClass.
EDIT
It turned out that the .hidden class was not defined. There are two possible solutions, you can choose either of them.
Solution1: replace .addClass("hidden") with .hide()
Solution2: Add the following rule to the CSS code: .hidden {display: none;}

Sending a list using RedirectToAction in MVC4

I am having the following code
public ActionResult Item_Post()
{
List<Product> products=new List<Product>() ;
int? total=0;
HttpCookie cookie= Request.Cookies["myvalue"];
if (Request.Cookies["myvalue"] != null)
{
int count = Request.Cookies["myvalue"].Values.Count;
var s = Request.Cookies["myvalue"].Value;
s = HttpUtility.UrlDecode(s ?? string.Empty);
string[] values = s.Split(',').Select(x => x.Trim()).ToArray();
for (int i = 1; i < values.Length; i++)
{
int id = Convert.ToInt32(values[i]);
Product product = db.Products.Single(x => x.Id == id);
total+=product.Price;
products.Add(product);
}
ViewBag.total = total;
TempData["products"]=products;
}
Session["prod"] = products;
return View("Buy", products);
//return RedirectToAction("Buy");
}
Now when I use only return View("Buy", products) I am getting the output and the Url remains same as I want to change the Url and when I use
return RedirectToAction("Buy", products);
I am getting error as I want to post the form to Buy. Are the parameters passed within the RedirectToAction appropriate or does it require anything else.
Here is the Action
#model IEnumerable<Shop_Online.com.Models.Product>
#{
ViewBag.Title = "Buy";
}
#using (Html.BeginForm())
{
<div style="width: 860px; margin: 0 auto" class="main">
<table border="1" style="font-family: Verdana; font-size: 13px">
<tr style="background-color: #f2f2f2">
<th colspan="4">ITEM</th>
<th>DELIEVERY DETAILS</th>
<th>QTY</th>
<th>SUB TOTAL</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td colspan="4" style="width: 46%">
<table style="font-family: Verdana; font-size: 13px">
<tr>
<td>
<img src="#Url.Content(item.Photo)" alt="Image" style="width:36px" />
</td>
<td>
#Html.DisplayFor(x => item.Model_Name)
</td>
</tr>
<tr>
<td style="color: #ccc">30 days Replacement</td>
</tr>
</table>
</td>
<td style="width: 39%">Free Delievery Delivered in 2-3 business days.</td>
<td style="width: 5%">1</td>
<td style="width: 50%"><b>Rs. #Html.DisplayFor(x => item.Price)</b></td>
</tr>
}
</table>
<div style="width: 100%; height: 70px; background-color: #f2f2f2">
<div style="width: 75%; height: 70px; float: left; font-family: Verdana; font-size: 13px">
</div>
<div style="width: 25%; height: 70px; float: left; font-family: Verdana; padding-top: 20px; font-size: 13px">
Estimated Price: <b>Rs.#ViewBag.total</b>
</div>
</div>
<div class="order" style="width: 100%; height: 70px">
<div class="left-order" style="width: 75%; height: 70px; float: left"></div>
<div class="left-order" style="width: 25%; float: left; height: 70px">
<input type="button" value="PLACE ORDER" style="border: 1px solid #ec6723; width: 216px; cursor: pointer; height: 45px; color: #fff; background: -webkit-linear-gradient(top,#f77219 1%,#fec6a7 3%,#f77219 7%,#f75b16 100%)" onclick="return confirm('Successfull placed order')" />
</div>
</div>
</div>
}
And now how should I replace the below code within my View If I use TempData
#foreach(var item in Model)
{
#Html.DisplayFor(model=>model.Name
/some more code/
}
You cannot get the list or any model objects passed to RedirectToAction in your action method. Because a RedirectToAction causes HTTP 302 (Redirect) request, which makes the browser to call GET request to the action.
You should use TempData to preserve the data in Item_Post action method.
public ActionResult Item_Post()
{
List<Product> products=new List<Product>() ;
int? total=0;
HttpCookie cookie= Request.Cookies["myvalue"];
if (Request.Cookies["myvalue"] != null)
{
some logic here
}
//save it to TempData for later usage
TempData["products"] = products;
//return View("Buy", products);
//return RedirectToAction("Buy", new {id=products});
return RedirectToAction("Buy");
}
And now in the Buy action use TempData to get your data.
[HttpGet]
public ActionResult Buy()
{
var products = TempData["products"];
//.. do anything
}
Hope this helps.
UPDATE
use the following code for Buy action.
[HttpGet]
public ActionResult Buy()
{
var products = TempData["products"] as List<Product>;
return View(products);
}
And now in the view, use foreach over the list of elements in the products
#model IEnumerable<Shop_Online.com.Models.Product>
#foreach (var item in Model)
{
<div>
Item Id: #item.Id
</div>
<div>
Item name: #item.Name
</div>
}
Now this should display you the list of all the items.
Or instead of assigning the TempData to an object of model class you can also try the following code which is the replacement for the above foreach.
#if (TempData["products"] != null)
{
foreach (var item in TempData["products"] as List<Product>)
{
<div>
Item Id: #item.Id
</div>
<div>
Item name: #item.Name
</div>
}
}
You can pass array of products as id from RedirctToAction.
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction%28v=vs.118%29.aspx
It accept RouteParamter or just value that you pass in query string of url.
If you want to use RedirectToAction then I suggest that you should use TempData.
public ActionResult Item_Post()
{
List<Product> products=new List<Product>() ;
int? total=0;
HttpCookie cookie= Request.Cookies["myvalue"];
if (Request.Cookies["myvalue"] != null)
{
some logic here
}
TempData["Products"] = products;
return RedirectToAction("Buy");
}
In your Buy Action
public ActionResult Buy()
{
// Get value from TempData
var products= (List<Product>)TempData["Products"];
}
Is your Buy ActionResult accept a List<Product> as a parameter, something like:
public ActionResult Buy(List<Product> ids)
{
...
}
Without this it will not know what to do with the list of products

how to show product in tabular format in MVC 4.0 (Razor)

Currently my data is showing in row like this
Item 1 Item 2 Item 3 Item 4 Item 5
I get this result using the following code
#using SportsStore.Models.WebUI
#model SportsStore.Models.ProductsListViewModel
#{
ViewBag.Title = "Products";
}
<div style="padding-left: 300px;">
<table style="height: 300px; border: 2px; border: 1px solid Red;">
<tr>
#foreach (var p in Model.Products)
{
<td style="height: 100px; width: 150px; border: 2px">
<a href="#Url.Action("Detail", "Product",
new { id = p.ProductID })">
<img alt="#p.ProductDescription" src="#p.Imagename" width="150" height="150"/>
<br />
Name : #p.ProductDescription<br />
Price : <span>#p.RetailPrice</span> </a>
</td>
}
</tr>
</table
</div>
I want to show my data like
Item 1 Item 2 Item 3 Item 4 Item 5
Item 6 Item 7 Item 8 Item 9 Item 10
Please Help me
Thanks in Advance
you can use divs. First set a width size for outher div, and set width size cell divs and float:left like following.
<div style="padding-left: 300px;width:750px;">
#foreach (var p in Model.Products)
{
<div style="height: 100px; width: 150px; float:left;">
<a href="#Url.Action("Detail", "Product",
new { id = p.ProductID })">
<img alt="#p.ProductDescription" src="#p.Imagename" width="150" height="150"/>
<br />
Name : #p.ProductDescription<br />
Price : <span>#p.RetailPrice</span> </a>
</div>
}
</div>
so, if your outher div width = 750 and cell divs width = 150 then you have 750/150 = 5 columns. so, its automaticly create 5 columns in per row.