I have the following code :
Controller method
public JsonResult GetNonstandardProgram(
int draw,
int start,
int length,
string search = null /* or string search or string[] search = null */
)
Posted data by datatables
...&search%5Bvalue%5D=somethingToSearch&search%5Bregex%5D=false
and I dont know how to handle this part
&search[value]=somethingToSearch
because in Controller passed string parameter 'search' is allways null.
What am I doing wrong ?
I figured it out, solution is to use
[Bind(Prefix = "search[value]")] string search
as parameter input
Related
I have widget and in the ActionResult method it get the query string as parameters. The widget takes the query string and calls a API. Is there anyway I can display a message to the view if its missing the query string?
Code
public ActionResult Index(string UserId, string BlogId)
Yep, do whatever you want
if(String.IsNullOrEmpty(UserId)){
// you get the idea
}
I would do one of the following
Add a property to the model, then handle that state in the view
Load a custom view that's just the message (cleanest)
Check for the empty querystring and do a return this.RedirectPermanent(url); to add the querystring to the page so there's no way it loads without something.
In the RavenDb documentation I can get the document Id if I pass in my object:
string orderId = session.Advanced.GetDocumentId(order); // "orders/1"
but what I would like is to just pass in the type and the object's id value instead, like:
string orderId = session.Advanced.GetDocumentId(typeof(Order), 1); // "orders/1"
Is this at all possible? If so, how? I'm trying to avoid having to pull the object out of the database before I delete it. I'm having RavenDb generate the collection names so I don't want to make any assumptions about the name.
You can get this from the document store's conventions, using the FindFullDocumentKeyFromNonStringIdentifier method.
Here's a simple extension method that will help:
public static string GetStringIdFor<T>(this IDocumentStore documentStore, int id)
{
return documentStore.Conventions.FindFullDocumentKeyFromNonStringIdentifier(id, typeof(T), false);
}
Now you can do this:
string orderId = documentStore.GetStringIdFor<Order>(1);
Or, if you don't happen to have access to the document store at that point in your code, you can grab it from the session:
string orderId = session.Advanced.DocumentStore.GetStringIdFor<Order>(1);
I have an ASP.NET MVC app. My views use Razor. At the top of my CSHTML file, I have the following:
#functions
{
public static HtmlString IsSelectedCss(string name)
{
string selected = ""; // Need to get value of "t" from query string
HtmlString attribute = new HtmlString("");
if (selectedTab.Equals(name, StringComparison.InvariantCultureIgnoreCase))
{
attribute = new HtmlString("class=\"active\"");
}
return attribute;
}
}
I need this function to examine the query string. Specifically, I need to get the value of the "t" query string parameter. My challenge is, I cannot seem to figure out how to get access to the QueryString in this function.
How do I get the value of a query string parameter in a Razor function?
Thanks!
The query string can be gotten from below.
HttpContext.Current.Request.QueryString["t"]
You need to make your function non-static, since the querystring is part of the request.
You can then write
HttpContext.Request.Query["t"]
You should really be doing this in the controller and pushing it through the model. But if you insist, you can simply use:
<%= Request["t"] %>
But why not read it in your controller?!
I am using web-api with mvc4
I am making searching functionality, in some cases like if i filter data then remove that textbox value and then press search button, need to show whole listing but in my case showing 400 bad request. as search parameter is blank, i know if search parameter blank then it will throw 400 error with web-api.
any one have proper solution then please let me know.
data: "CurrPage=" + JsCurrPage + "&PageSize=" + parseInt(pagesize) + "&BuildTypeName=" + $("#BuildTypeName").val(),
Here in some cases BuildType is blank. when search made
//controller
public HttpResponseMessage GetBuildTypeList(int CurrPage, int PageSize, string BuildTypeName)
{
}
Net -> XHR URL is :
http://{parentURL}/api/BuildTypeWebApi/GetBuildTypeList?CurrPage=1&PageSize=10&BuildTypeName=
public HttpResponseMessage GetBuildTypeList(string BuildTypeName, int CurrPage = 1, int PageSize = 0)
In you business logic you can assume that a PageSize of 0 means all records.
If you allow CurrPage and PageSize to be empty, then you need to accept nullable ints:
public HttpResponseMessage GetBuildTypeList(int? CurrPage, int? PageSize, string BuildTypeName)
Then, you'll update the query so it return the entire list if no filter values are provided.
I've written a custom workflow action that takes in several values, mostly using the SingleLineInput control.
When I assign literal values, I have no issues, but when I try to assign a Workflow Variable, I don't get the actual value of the variable, I get the literal text - something like {WorkflowVariable:XmlValue} - assuming my variable was names XmlValue.
I'm not sure what I could possibly be doing wrong. Any ideas?
Here's code snippets:
The javascript for retrieving the value from the SingleLineInput
function TPAWriteConfig() {
configXml.selectSingleNode("/NWActionConfig/Parameters/Parameter[#Name='FieldValue']/PrimitiveValue/#Value").text = getRTEValue('<%=fieldValue.ClientID%>');
SaveErrorHandlingSection();
return true;
}
The server control:
<Nintex:ConfigurationProperty ID="ConfigurationProperty3" runat="server" FieldTitle="Field Value" RequiredField="True">
<TemplateControlArea>
<Nintex:SingleLineInput runat="server" id="fieldValue"></Nintex:SingleLineInput>
</TemplateControlArea>
</Nintex:ConfigurationProperty>
From my adapter class:
private const string FieldValueProperty = "FieldValue";
NWActionConfig config = new NWActionConfig(this);
config.Parameters[2] = new ActivityParameter();
config.Parameters[2].Name = FieldValueProperty;
config.Parameters[2].PrimitiveValue = new PrimitiveValue();
config.Parameters[2].PrimitiveValue.Value = string.Empty;
config.Parameters[2].PrimitiveValue.ValueType = SPFieldType.Text.ToString();
From the activity class:
public static DependencyProperty FieldValueProperty = DependencyProperty.Register("FieldValue", typeof (string),
typeof (
WriteOnePdfFieldActivity));
public string FieldValue
{
get { return (string) GetValue(FieldValueProperty); }
set { SetValue(FieldValueProperty, value); }
}
I feel a little silly answering my own question, but for the sake of anyone else having the same issues. Here's how it works:
If you're putting a literal value in the field, just use the value
If you're using any other kind of assignment, do a lookup based on the value.
The code below demonstrates:
var fieldValue = FieldValue.StartsWith("{") ? ctx.AddContextDataToString(FieldValue, true) : FieldValue;
This extract the value from the workflow context. Hope this helps.