Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to submit data using partail View.How do I do it? Can someone send simple sample code for understand it?
I want to create comment box as partail view.
If you give your Html here, it would have been helpful.
I recommend that you use the ID of the <input> tag and SUBMIT the value of it to your server via ajax call.
var comments = $('#Comment_Box_ID').val();
$.ajax({
type: 'post',
url: '/controller/method/',
data: comments,
success: function (data) {
// success code
},
error: function (e) {
// error code
}
});
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have been using asp MVC model state error when handling errors.
currently, I was using temp data as you see below:
TempData["message"] = "Successfully Added New Data.";
and rendered in all my views with forms.
I just want to ask any best practice that can be used when it comes to handling success message/status.
TIA!
If you are redirecting to another view you can use TempData collection. If you are staying on the same view, I would return current view with a flag in the model and then render it base on the value or just use ViewBag.
You should include the error or success message in the model you sent to the view.
Something like that:
public async Task<IActionResult> CityDetails()
{
MyModel MyModel = new MyModel();
MyModel.Message = "Successfully Added New Data.";
return View(MyModel);
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I created a product registration page using ASP.Net MVC. I need to implement the same product registration page for subsidiaries (maybe 3 or 4) with a few minor changes to the way the site looks. For example, the logo will be different and some text at the top of the page. What is the best way to use the same codebase?
The best option I could come up with is passing HttpContext.Current.Request.URL to the view and using java script to update it.
However, I know routing can be an option too.
If you will be keeping the same .cshtml view for all registration pages then i think creating a partial view for logo generation would probably help you out.
Add another variable to your view model.. maybe call it subsidiary?
public int Subsidiary { get; set; }
then create a partial view called something like _LogoPartial.cshtml and in there do a if statement on the Subsidiary variable and return a different logo based on it
#model int
#if (Model == 1)
{
<img src="something" />
}
else if ...
then in your main view call it with
Html.RenderPartial("~/Views/Shared/_LogoPartial", Model.Subsidiary);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How to show Last Ten Pages Visited Cookie with asp.net mvc?
To store the url for each accessed page, you can use the Application_BeginRequest method of the global.asax, which will be called whatever the page accessed.
Example :
protected void Application_BeginRequest(object sender, EventArgs e)
{
string currentUrl = this.Context.Request.Url.AbsolutePath;
// Store the currentUrl to your database, for example
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have an application which uses MVC and KnockoutJS. In my application is a grid in a view which shows a knockout observable array bound as data to a html grid.
I want to navigate to another view when a user clicks on any of the row from the grid. When a user clicks on any row I capture the id from that row, and call a javascript method which uses Ajax to invoke an action method from a controller.
I am able to call the action method from javascript method using $.ajax, but I am not able to redirect to the other view.
How can this be done?
You can handle the success callback and call window.location.href to the action method which will return your view
$.ajax({
type: "POST",
url: url,
data: data,
success: callbackmethod,
dataType: dataType
});
function callbackMethod() {
window.location.href = "/YourController/YourView"
}
In the Controller
public ActionResult YourView()
{
//Any processing
return View(YourViewModel);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a required field, string attribute { get; set } in a class and want to set its value in Razor. Is something like the following possible?
#model.attribute = "whatever'
Close. #model is how you declare the model for your view. Your view should have a Model property, so you can do this:
#{
Model.attribute = "whatever";
}