passing data to modal dialog from controller to partial view with viewmodel MVC Ajax - asp.net-mvc

I want to pass data to modal dialog from my controller to partial view using view model but it isn't working.
When I tried passing data to my view model without modal dialog and it's fine for the result
I have put debug points and showing the value in my view model return to my partial view but it isn't displaying anything.
Code in my View
<div class="col-sm-btn">
<button type="button" id="btnSearchType" class="btn bg">
<i class="material-icons">search</i>
</button>
</div>
#Html.Partial("~/Views/Dialog/Type.cshtml");
<script>
$("#btnSearchType").click(function () {
$.ajax({
type: "GET",
url: '#Url.Action("ListType", "MasterMaterial")',
data: {
category: $("#txtCategory").val()
},
dataType: "html",
success: function (response) {
$('#type').modal('show');
},
error: function (response) {
alert("error");
}
});
});
Code in my Partial View
#model List<MVC_Client.Models.MasterType>
<div class="modal fade" id="type" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="defaultModalLabel">Type</h4>
</div>
<div class="modal-body">
<div class="table-responsive">
<table id="listType" class="js-basic-example dataTable">
<thead>
<tr>
<th>Type Code</th>
<th>Type Namce</th>
</tr>
</thead>
<tbody>
#if (Model != null)
{
foreach (var type in Model)
{
<tr>
<td>#type.TypeCode</td>
<td>#type.TypeName</td>
</tr>
}
}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
Code in my Controller
[HttpGet]
public ActionResult ListType(string category)
{
MasterTypeClient mtc = new MasterTypeClient();
List<MasterType> listType = new List<MasterType>();
listType = mtc.GetListTypes(category).ToList();
return PartialView("~/views/DialogPages/Type.cshtml", listType);
}
Code in my Model Client
public IEnumerable<MasterType> GetListTypes(string category)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(BASE_URL);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("MasterType/Category/" + (category)).Result;
if (response.IsSuccessStatusCode)
return response.Content.ReadAsAsync<IEnumerable<MasterType>>().Result;
return null;
}
Code in my Model
public class MasterType
{
public string TypeCode { get; set; }
public string TypeName { get; set; }
}
And here is for the result
Result for my modal dialog

You're loading your PartialView when the View loads. It looks like you want to only show the modal PartialView after search is clicked.
I would go ahead and put the modal structure in the View and change the PartialView to just generate the table. Something like:
View
<div class="col-sm-btn">
<button type="button" id="btnSearchType" class="btn bg">
<i class="material-icons">search</i>
</button>
</div>
<div class="modal fade" id="type" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="defaultModalLabel">Type</h4>
</div>
<div class="modal-body table-placeholder">
</div>
</div>
</div>
</div>
<script>
$("#btnSearchType").click(function () {
$.ajax({
type: "GET",
url: '#Url.Action("ListType", "MasterMaterial")',
data: {
category: $("#txtCategory").val()
},
dataType: "html",
success: function (response) {
$('.table-placeholder').html(response);
$('#type').modal('show');
},
error: function (response) {
alert("error");
}
});
});
Partial View
#model List<MVC_Client.Models.MasterType>
<div class="table-responsive">
<table id="listType" class="js-basic-example dataTable">
<thead>
<tr>
<th>Type Code</th>
<th>Type Namce</th>
</tr>
</thead>
<tbody>
#if (Model != null)
{
foreach (var type in Model)
{
<tr>
<td>#type.TypeCode</td>
<td>#type.TypeName</td>
</tr>
}
}
</tbody>
</table>
</div>

Related

How do I access query data in modal popup

This seems like it should be simple but nothing is in ASP.NET Core MVC. I would simply like to present the results of a query in a table inside a modal popup. The modal is opening but the table is empty. Not just that but the table is getting created before I even click the button to show the modal. I'm hoping some kind person out there can help me.
This is the controller action method:
public async Task<IActionResult> GetStudies(int id)
{
var results2 = (from s in _context.Studies
join sn in _context.StudyNodes on s.Id equals sn.StudyId
where sn.NodeId == id
select new BundleNodeViewModel
{
StudyId = s.Id,
StudyName = s.Name
}).ToList();
return Ok(results2);
}
This is the function calling the action:
getStudies = (url, id) => {
$.ajax({
type: 'GET',
url: url,
data: {
'id': id
},
success: function (res) {
console.log(res);
$("#formModal").find(".modal-body").html(res.Name);
$("#formModal").find(".modal-title");
$("#formModal").modal('show');
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
console.log(response);
alert("error");
}
})
};
And this is the modal popup:
<div id="formModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" id="close_" style="background-color:transparent; color:aquamarine; border-style:none">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Assigned Studies</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="row">
<div class="col-md-4">
<form asp-action="Bind" asp-controller="Studies">
<div class="form-group">
<table class="table table-hover" style="height: 300px">
<thead>
<tr class="position-sticky" style="color:aliceblue; background-color:#126E75">
<th class="text-start">
Study
</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr class=" table-light">
<td class="text-start">
#item.StudyName
</td>
</tr>
}
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<input type="button" id="btnClosePopup" value="Close" data-dismiss="modal" class="btn btn-danger" />
</div>
</div>
</div>
</div>
I'm really confused about the order in which things are happening. For some reason the code in the modal runs when the parent page is loaded and not when you click the button on the parent page to open the modal. So the model in the foreach() statement is not the model I need it to be. When I click on the open modal button I expect it to go to the controller, get the data and return it to the modal where I can loop through the object and create a table.
Any ideas anyone?
I didn't understand your question but I have tried to do what you might want to do.
we have created dummy data which should you get from the ajax.
If you don not want to open the modal on page load please remove the Document Ready part.
try to place the 'getStudies' function body to your ajax's success block.
$(document).ready(()=>{
getStudies();
});
var data = [
{ 'StudyId': 1,'Name':"STD 10"},
{'StudyId' : 2,'Name':"STD 11"}
];
let getStudies = (url, id) => {
$("#formModal").find("tbody").html('');
$.each(data,(index,val) =>
{
let tr=`<tr class="table-light"><td class="text-start">${val.Name}</td></tr>`;
$("#formModal").find("tbody").append(tr);
});
$("#formModal").modal('show');
};
<html>
<head>
<title>kaushal</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body> <button onClick="getStudies()">open modal</button>
<div id="formModal" style="width:100%;border:1px solid red;" class="modal fade in" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" id="close_" style="background-color:transparent; color:aquamarine; border-style:none">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Assigned Studies</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="row">
<div class="col-md-4">
<form asp-action="Bind" asp-controller="Studies">
<div class="form-group">
<table class="table table-hover" style="height: 300px">
<thead>
<tr class="position-sticky" style="color:aliceblue; background-color:#126E75">
<th class="text-start">
Study
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<input type="button" id="btnClosePopup" value="Close" data-dismiss="modal" class="btn btn-danger" />
</div>
</div>
</div>
</div>
</body>
</html>

Best practice to show search result in a popup modal in ASP.NET MVC Core

I am passing a value (search string) from a form to a controller action method where I perform some activities to find specific records from the db then passing the result to either ViewBag or to a model in order to display the result in a view.
The easy way is to pass the result as a model (or viewmodel) to the view .. something like:
1- Pass the string from a form to the controller.
2- in the controller, method, after performing the search and saving it to a list/var ..
return View(mymodel);
3- in the view .. we can say
#foreach (var item in Model)
{
... table here to display the columns and the data..etc.
}
The question is, in stead of the view, how can I display the result in a modal popup ?
There are so many suggestions with many different JQuery or JavaScripts but is there any easier solution?
is there anything like (simply) show me the view in a popup modal ?
Thanks in advance
is there anything like (simply) show me the view in a popup modal ?
I think the simpest way to display the result in a modal popup is using partial view and ajax.
Here, you cannot avoid creating a view to store the content that needs to be displayed in the modal popup. Of course, you only need to create a partial view instead of a view.
Here is a simple demo for your reference:
main view:
Update:
#{
ViewData["Title"] = "Testpop";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>Testpop</h1>
<form>
<input id="Text1" type="text" />
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" id="showPop">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body ">
<div id="popup">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal" id="submitModal">Submit</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</form>
#section Scripts{
<script>
$('#showPop').click(function () {
var url = '#Url.Action("GetPartialView", "Default")';
$.ajax({
url: url,
type: 'post',
data: { "para": $("#Text1").val()},
success: function (data) {
$('#popup').html(data);
}
});
})
$('#submitModal').click(function () {
var url = '#Url.Action("GetData", "Default")';
$.ajax({
url: url,
type: 'post',
data: { "data": $("input[name='data']").val() },
success: function () {
$("#Text1").val("");
alert("pass successfully!");
}
});
});
</script>
}
Default/GetPartialView action:
[HttpPost]
public IActionResult GetPartialView(string para)
{
//get data
var model = _context.Person.Where(x=>x.Name == para).ToList();
return PartialView("_PopView",model);
}
_PopView.cshtml partial view:
#model IEnumerable<Person>
<table class="table table-bordered">
<tr>
<td>Id</td>
<td>Name</td>
<td>Nome_Tipo</td>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#item.Id
</td>
<td>
#item.Name
</td>
<td>
#item.Nome_Tipo
</td>
</tr>
}
</table>
<input id="data" type="text" name="data" />
pop up submit data to the action:
[HttpPost]
public IActionResult GetData(string data)
{
//do anything.
return Ok();
}
Here is the new result:

Change modal form depending on the button clicked

I have a table showing the information of the users, with an edit button for each one.
I want to show a modal form with the details for the user I want to edit, but I don't know how to get the details from the list, and passing them to the modal as a model.
Here is my View:
#model MyApp.Models.User
#{
ViewBag.Title = "Users";
var roles = new List<string> { "Manager", "Admin" };
var userRoles = (List<string>)ViewData["userRoles"];
}
<h2>#ViewBag.Title</h2>
#if (userRoles.Any(u => roles.Contains(u)))
{
using (Html.BeginForm("Update", "Admin", FormMethod.Post, new { id = "update-form", value = "" }))
{
<div class="modal fade" id="user-editor" >
<div class="modal-header">
<a class="close" data-dismiss="modal"><h3>×</h3></a>
<h3 id="modal-title">Edit User</h3>
</div>
<div class="modal-body">
<div class="form-group">
#Html.Label("Name", new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.Name, new { #class = "form-control" })
</div>
</div>
<div class="form-group">
#Html.Label("Age", new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.Age, new { #class = "form-control" })
</div>
</div>
</div>
<div class="modal-footer">
<a class="btn" data-dismiss="modal">Close</a>
<input type="submit" class="btn btn-primary" value="Save Changes" />
</div>
</div>
}
}
<table class="table-bordered table-hover" id="tbusers">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
#if (userRoles.Any(u => roles.Contains(u)))
{
<th>Edit</th>
}
</tr>
</thead>
<tbody>
#foreach (var u in users)
{
<tr id="#u.Id">
<td>#u.Name</td>
<td>#u.Age</td>
#if (userRoles.Any(u => roles.Contains(u)))
{
<td><a type="button" class="btn edit-btn" href="#user-editor" data-toggle="modal">Edit</a></td>
}
</tr>
}
</tbody>
</table>
I've created a testing sample which will help you understand how can you achieve this.
Index.cshtml which will show a list of employees
#model IEnumerable<MvcApplication1.Models.Employee>
#using MvcApplication1.Models;
<h2>Index</h2>
<table>
#foreach (Employee item in Model)
{
<tr>
<td>#Html.ActionLink(#item.EmployeeName, "Name", new { id = item.ID })</td>
<td>
<button type="button" data-id='#item.ID' class="anchorDetail btn btn-info btn-sm" data-toggle="modal"
data-target="#myModal">
Open Large Modal</button></td>
</tr>
}
</table>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Details</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
At the same page, reference the following scripts
<script src="~/Scripts/jquery-3.1.1.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
JQuery AJAX call for getting/setting the data of individual employee from ActionMethod at the same page
<script>
$(document).ready(function () {
var TeamDetailPostBackURL = '/Employee/Details';
$(document).on('click', '.anchorDetail', function () {
var $buttonClicked = $(this);
var id = $buttonClicked.attr('data-id');
var options = { "backdrop": "static", keyboard: true };
$.ajax({
type: "GET",
url: TeamDetailPostBackURL,
contentType: "application/json; charset=utf-8",
data: { "Id": id },
datatype: "json",
success: function (data) {
debugger;
$('.modal-body').html(data);
$('#myModal').modal(options);
$('#myModal').modal('show');
},
error: function () {
alert("Dynamic content load failed.");
}
});
});
$("#closbtn").click(function () {
$('#myModal').modal('hide');
});
});
Now Create a class of Employee(because i'm not using EF)
public class Employee
{
public int ID { get; set; }
public string EmployeeName { get; set; }
}
Create controller named Employee and 2 ActionMethods like these:
public ActionResult Index()
{
return View(emp);//sends a List of employees to Index View
}
public ActionResult Details(int Id)
{
return PartialView("Details",
emp.Where(x=>x.ID==Convert.ToInt32(Id)).FirstOrDefault());
}
I'm returning PartialView because I need to load a page within a page.
Details.cshtml
#model MvcApplication1.Models.Employee
<fieldset>
<legend>Employee</legend>
<div class="display-label">
#Html.DisplayNameFor(model => model.ID)
</div>
<div class="display-field">
#Html.DisplayFor(model => model.ID)
</div>
<div class="display-label">
#Html.DisplayNameFor(model => model.EmployeeName)
</div>
<div class="display-field">
#Html.DisplayFor(model => model.EmployeeName)
</div>
</fieldset>
<p>#Html.ActionLink("Back to List", "Index")</p>
When you execute and visit the Index page of Employee, you'll see screen like this:
And the Modal Dialog with results will be shown like this:
Note: You need to add reference of jquery and Bootstrap and you can further design/customize it according to your needs
Hope it helps!

Boostrap Modal not working on ASP.NET MVC

I have readed a lot of blogs and articles about showing MVC partial views using Boostrap modals. It seems that I have exactly what I'm seen on the material consulted but still it doesn't show the modal. I just need to show the partial view with the Album details in a modal. The controller is working fine when I load the URL through the browser.
This is the Index HTML code where the modal is shown:
<tbody>
#foreach( var album in Model.Albums)
{
<tr data-toggle="modal" data-target="#albumModal" data-url="#Url.Action("Album", new { id = album.Id })">
<td>#album.Title</td>
<td>#album.Artist</td>
<td>#album.Genre</td>
<td>#album.Year</td>
</tr>
}
</tbody>
Partial View
<div class="modal fade" id="albumModal" tabindex="-1" role="dialog" aria-labelledby="albumModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="albumModalLabel">Album Details</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-4">
<div class="row">
<label>Album<input class="form-control" type="text" id="title" /></label>
</div>
<div class="row">
<label>Artist <input class="form-control" type="text" id="artist" /></label>
</div>
<div class="row">
<label>Genre <input class="form-control" type="text" id="genre" /></label>
</div>
<div class="row">
<label>Year <input class="form-control" type="text" id="year" /></label>
</div>
</div>
<div class="col-md-8">
<table class="table table-condensed table-striped">
<thead>
<tr>
<th>Track</th>
<th>Song Title</th>
<th>Length</th>
</tr>
</thead>
<tbody class="tracks"></tbody>
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
HomeController
[HttpGet]
public ActionResult Album(int? id)
{
if (id == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
var albumInfo = _service.GetAlbumInfo((int) id);
if (albumInfo == null) return HttpNotFound();
return PartialView("_Album", albumInfo);
}
Script
$(document).ready(function() {
$('.list-element').click(function () {
debugger;
var $buttonClicked = $(this);
var url = $buttonClicked.attr('data-url');
$.get(url, function (data) {
$('#albumContainer').html(data);
$('#albumModal').modal('show');
});
});
});
In almost all of the SO questions counsulted, they wasn't using data-target but I am. What do I need to modify to achieve that the modal shows?
VIEW
#model ShowModal
<table>
<tbody>
<tr data-toggle="modal" data-target="#albumModal" data-url="#Url.Action("Album", new { id = album.Id })">
<td>#album.Title</td>
<td>#album.Artist</td>
<td>#album.Genre</td>
<td>#album.Year</td>
</tr>
</tbody>
</table>
<!-- Modal -->
<div class="modal" id="albumModal" tabindex="-1" role="dialog" aria-labelledby="albumModal">
#Html.Partial("_albumPartial", Model)
</div>
CONTROLLER
[HttpGet]
public ActionResult Album(int? id)
{
ShowModal modal = new ShowModal();
var albumInfo = _service.GetAlbumInfo((int) id);
modal.Info1 = albumInfo.Info1;//and other fields
return PartialView("_albumPartial", modal);
}
SCRIPT
<script>
$(document).ready(function () {
$("#albumModal").on("show.bs.modal", function (e) {
var button = $(event.relatedTarget) // Button that triggered the modal
var url = button.data('url') // or button.attr("data-url") or get here just the id and create the URL here
$.get(url, function (data) {
$('#albumModal').html(data);
$('#albumModal').modal('show');
});
});
});
</script>

How can I send to view a DTO and Model

My Dto
public class homePageDTO
{
public IEnumerable<Yazi> yazi { get; set; }
public IEnumerable<Yorum> yorum { get; set; }
}
My ActionMethod
public ActionResult Post(int pid)
{
homePageDTO obj = new homePageDTO();
obj.yazi = ent.Yazi.Where(x=>(x.YaziID==(int)pid)).ToList();
obj.yorum = ent.Yorum.Where(x => (x.YorumNo == (int)pid)).ToList();
return View(obj);
}
My multi model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication15.Models
{
public class BigViewModel
{
public homePageDTO home { get; set; }
public Yorum Yorrum { get; set; }
}
}
My View
#model WebApplication15.Models.BigViewModel
#{
ViewBag.Title = "Post";
Layout = "~/Views/Shared/_Layout.cshtml";
}
#foreach (var item in Model.home.yazi)
{
<header class="intro-header" style="background-image: url('/content/img/post-bg.jpg')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="site-heading">
<h1>#item.YaziUstBaslik</h1>
<hr class="small">
<span class="subheading"><b>#item.YaziAltBaslik</b></span>
</div>
</div>
</div>
</div>
</header>
<!-- Post Content -->
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<p>#item.Yazi1</p>
<p class="alert alert-warning">Yollayan #item.YazarKullaniciAdi-#item.YaziTarih</p>
</div>
</div>
</div>
</article>
<hr>
}
<h2>Index</h2>
<table class="table">
<tr>
<th>
Yorum
</th>
<th>
Yorum Sahibi
</th>
<th>
Tarihi
</th>
<th></th>
</tr>
#foreach (var x in Model.home.yorum)
{
<tr>
<td>
#x.Yorum1
</td>
<td>
#x.YorumSahibi
</td>
<td>
#x.YorumTarihi
</td>
</tr>
}
</table>
<div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Yeni Yorum</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Selam</h4>
</div>
<div class="modal-body">
<p>nasdsadasdasda</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Yolla</button>
</div>
</div>
</div>
</div>
</div>
ERROR
The model item passed into the dictionary is of type 'WebApplication15.Models.homePageDTO', but this dictionary requires a model item of type 'WebApplication15.Models.BigViewModel'.
It was dissolved
My new action method
public ActionResult Post(int pid)
{
BigViewModel bigyorum = new BigViewModel();
bigyorum.home = new homePageDTO();
bigyorum.home.yazi = ent.Yazi.Where(x=>(x.YaziID==(int)pid)).ToList();
bigyorum.home.yorum = ent.Yorum.Where(x => (x.YorumNo == (int)pid)).ToList();
return View(bigyorum);
}
you need to change the model that is related in the view, in the first line of the view set this:
#model WebApplication15.Models.homePageDTO
I think homePageDTO is in the namespace WebApplication15.Models, if not, put the correct namespace.
With your update:
In your action, you are passing an object of type homePageDTO:
public ActionResult Post(int pid)
{
homePageDTO obj = new homePageDTO();
obj.yazi = ent.Yazi.Where(x=>(x.YaziID==(int)pid)).ToList();
obj.yorum = ent.Yorum.Where(x => (x.YorumNo == (int)pid)).ToList();
return View(obj);
}
and in your view, yo have:
#model WebApplication15.Models.BigViewModel
There are differents objects, the type of the object that you pass from the action to the view, must be the same that you declare in the view.
So, change the action to return a BigViewModel or change in your view to homePageDTO

Resources