Click here to Skip to main content
15,885,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
it should returning page View instead of pop-up which full of html code.

View

HTML
@model SendAFaxWeb.Models.Home
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>GetHistory</title>
</head>
<body>
    <div>
        <h2>Fax History List Test</h2>
        <form action="@Url.Action("GetHistory", "Home")" id="form" method="post" enctype="multipart/form-data">
            <table class="table table-condensed">
                @foreach (var item in Model.Documents)
            {
                    <tr>
                        <td>@item.Name</td>
                        <td>@item.Path</td>
                        <td>
                            <button class="btn btn-xs btn-danger" onclick="d(@item.Name)">
                                <span class="glyphicon glyphicon-trash"></span>
                            </button>
                        </td>
                    </tr>
                }
            </table>
       </form>
</div>
</body>
</html>


controller

C#
public ActionResult GetHistory()
{
  //some code here
  return View(history)//list of object
}


What I have tried:

i have tried to return nothing, but still show popup html. how to put an image in here btw?
Posted
Updated 16-Aug-16 3:13am
Comments
Karthik_Mahalingam 16-Aug-16 0:28am    
what is the exact issue?
you cannot put image here, instead you can host in any open image hosting site and share the url.
http://imgur.com/
wa.war 16-Aug-16 0:32am    
http://imgur.com/a/MCHn0

take a look the image here.
Karthik_Mahalingam 16-Aug-16 0:34am    
post the full cshtml,
you are showing it in alert box
wa.war 16-Aug-16 2:42am    
i'm not showing any alert box, like you can see my code above.
Karthik_Mahalingam 16-Aug-16 2:43am    
but the sccreenshot shows alertbox

1 solution

I guess, your alert box is an error view (which is also HTML formatted). I would say (after looking in my glass sphere) your Model definition is not correct.

Your model reference:
C#
@model SendAFaxWeb.Models.Home

looks very strange as well. Are you sure, your ViewModel is called "Home"?

And your Controller Action "GetHistory"
C#
public ActionResult GetHistory()
{
  //some code here
  return View(history)//list of object
}

what is its result? Your mentioned view? What for? To submit the form again? (... and again, and again, and again...)

I hope, (assuming your ViewModel name is Home) you have:

C#
// for the very first call 
[HttpGet]
public ActionResult GetHistory()
{
    SendAFaxWeb.Models.Home history = new SendAFaxWeb.Models.Home();
    //some code to set the model properties here
    history.Documents = GetDocuments(); // or so...
    return View(history)//not a list of objects, but a model containing list of objects
}

//for the posted data from your form
[HttpPost]
public ActionResult GetHistory(SendAFaxWeb.Models.Home history)
{
    //some update actions...

    //after the job is done, redirect to Index
    return RedirectToAction("Index","Home")
}


If you need to update just a part of the View, it is better to use f. ex. jquery ajax function and update the html content.

Example:

The matching html element:

HTML
<div id="yourdivname">
</div>


The javascript / jquery function (assuming, the input text "myParamTextBox" has your parameter for query:

JavaScript
getUpdatedDivContent = function () {
	var id = $("#myParamTextBox").val();
	$.ajax({
		url: '@Url.Action("UpdateMyDivContent", "Home")',
		type: 'GET',
		datatype: 'json',
		traditional: true,
		data: { myparameter: id },
		error: function (data) {
			alert($(data.responseText));
		},
		success: function (jsonresponse) {
			$("#yourdivname").html(jsonresponse);
		}
	});
};



If you want to have a pretty nice formatted div content, you can return a partial view to the ajax function.

C#
[HttpGet]
public ActionResult UpdateMyDivContent(string myparameter)
{
    //if the "Create" static function is defined
    MyVeryNiceViewModel model = MyVeryNiceViewModel.Create(myparameter);
    model.MyProperty1 = "What ever 1";
    model.MyProperty2 = "What ever 2";
    model.MyProperty3 = "What ever 3";

    return PartialView("_yourUpdatedContent", model);
}


By the way: your form has an id="form". I'm not sure, if this is the happiest idea for an element name. It shouldn't however cause your issue here.
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900